C# 代理的生成在一个环境中可以正常工作,但在另一个环境中却不行?
我有一个简单的Webserivce(WCF)托管在Windows服务(Selfhost)中。服务的声明如下所示:C# 代理的生成在一个环境中可以正常工作,但在另一个环境中却不行?,c#,wcf,web-services,proxy,wsdl,C#,Wcf,Web Services,Proxy,Wsdl,我有一个简单的Webserivce(WCF)托管在Windows服务(Selfhost)中。服务的声明如下所示: <service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration"> <endpoint binding="basicHttpBinding"
<service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration">
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicMyAppIntegration" bindingNamespace="MyApp.ServiceImplementation" contract="MyApp.ServiceContracts.IMyAppIntegration"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8008/MyAppServiceutv/Integration"/>
</baseAddresses>
</host>
</service>
在Visual Studio 2012中添加服务引用时,出现以下异常:
例外情况
该文件已被理解,但无法处理
- WSDL文档包含无法解析的链接
- 下载“
”http://localhost:8008/MyAppServiceutv/Integration?xsd=xsd0
- 无法连接到远程服务器
http://MyComputer:8008/MyAppServiceutv/Integration?wsdl
”。
内容类型应用程序/soap+xml;服务http://MyComputer:8008/MyAppServiceutv/Integration?wsdl
。客户端和服务绑定可能不匹配。
远程服务器返回错误:(415)无法处理消息,因为内容类型为“application/soap+xml”;charset=utf-8“不是预期的类型”text/xml;字符集=utf-8'。。
如果服务是在当前解决方案中定义的,请尝试构建解决方案并再次添加服务引用
移动到开发环境
将服务移动到开发人员计算机时,一切都很好?为什么我会在一个环境中遇到上述问题?这可能是由于强大的安全限制造成的吗?听起来您的VS2012实例与服务主机脱离了机箱。尝试像这样更改您的配置
<service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration">
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicMyAppIntegration" bindingNamespace="MyApp.ServiceImplementation" contract="MyApp.ServiceContracts.IMyAppIntegration"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://{my fully qualified domain name}:8008/MyAppServiceutv/Integration"/>
</baseAddresses>
</host>
</service>
好的。现在我已经确认了这个问题…一个解释。NET4.0或更低版本的WCF生成多文件WSDL文件。基本WSDL文件链接到各种文件。WDSL文件中的链接使用绝对URI而不是相对URI链接到其他文件。因此,当VisualStudio尝试查找其他WDSL文件时,在“localhost”上找不到它
使用.NET4.5WCF可以生成单文件WSDL,这也将解决您的问题。但总的来说,我认为WCF 4.0在处理WSDL代理生成时被破坏了。服务是否在Cassini中运行?如果是这样,则无法从其他计算机调用该服务,您需要将其发布到IIS,因为该服务不是作为Windows服务自托管的。在dev计算机上生成代理没有问题,但是当将其全部移动到这个更安全的环境中时,这是不允许的?端口8008是否配置为接受流量?您可能需要从VS.NET 2010命令提示符中使用此命令,如图所示:netsh http add urlacl url=http://+:8008/user=\everyone.@Rajesh可能就是这样,您的意思是我可以通过键入该行直接从Visual Studio 2010 GUI设置正确的权限吗?我将尝试此操作。它将通过命令promptYes完成。在这个失败的环境中,服务将放置在服务器上。您的意思是不能在此服务器上使用localhost吗?为什么它在所有其他环境中都工作得如此出色,但在这个环境中却不行?
<service behaviorConfiguration="MyApp.ServiceImplementation.MyAppIntegration_Behavior" name="MyApp.ServiceImplementation.MyAppIntegration">
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicMyAppIntegration" bindingNamespace="MyApp.ServiceImplementation" contract="MyApp.ServiceContracts.IMyAppIntegration"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://{my fully qualified domain name}:8008/MyAppServiceutv/Integration"/>
</baseAddresses>
</host>
</service>