WCF 服务绑定 wsHttp 与无需身份验证的基本绑定
我正在尝试创建具有匿名身份验证的 WCF 服务。当我将服务部署到不在当前域中的目标服务器时,我在尝试调用它时收到以下错误:
内容类型application/soap+xml; 不支持 charset=utf-8 服务http://myserver.com/page.svc。 客户端和服务绑定可能是 不匹配。
就目前情况而言,我的 web.config 文件中有该服务的以下部分:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
我一直在尝试各种绑定(wsHttpBinding 和 basicHttpBinding),但我要么收到上述错误(使用 basicHttpBinding),要么收到“访问被拒绝”消息(使用 wsHttpBinding)。这是我在使用 wsHttpBinding 时尝试使用的 web.config 部分
<system.serviceModel>
<services>
<service behaviorConfiguration="AMP.MainBehavior" name="AMP.Main">
<endpoint address="" binding="wsHttpBinding" contract="AMP.IMain">
<identity>
<dns value="myservice.com"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AMP.MainBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
该服务是使用 .NET 4.0 框架创建的。我需要匿名,但我不确定我错过了什么。我是 WCF 新手,所以我还没有把所有事情都安排好。
谢谢你,
I am attempting to create a WCF service with anonymous authentication. When I deploy the service to the destination server that is not on my current domain I receive the following error when attempting to call it:
Content Type application/soap+xml;
charset=utf-8 was not supported by the
service http://myserver.com/page.svc.
The client and service bindings may be
mismatched.
as it stands now I have the following section in my web.config file for the service:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
I have been trying various bindings (wsHttpBinding and basicHttpBinding) but I either receive the error above (using basicHttpBinding) or an "Access is Denied" message (using wsHttpBinding). Here is the web.config section I tried to use when using wsHttpBinding
<system.serviceModel>
<services>
<service behaviorConfiguration="AMP.MainBehavior" name="AMP.Main">
<endpoint address="" binding="wsHttpBinding" contract="AMP.IMain">
<identity>
<dns value="myservice.com"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AMP.MainBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The service has been created with the .NET 4.0 framework. I need it to be anonymous but I'm not sure what I'm missing. I'm new to WCF so I don't have all my ducks in a row yet.
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误表明您发送的 HTTP 请求的内容类型不受支持。提到的内容类型在 SOAP 1.2 中使用,但 BasicHttpBinding 使用具有不同内容类型(text/xml;charset=utf-8)的 SOAP 1.1。因此,您的服务和客户端配置之间可能存在一些不匹配。
在第二个示例中,问题是默认的 WsHttpBinidng 配置。默认情况下,WsHttpBinding 通过消息安全和 Windows 身份验证进行保护 =>例外,因为计算机位于不同的域中,因此 Windows 身份验证无法工作。您必须定义自己的 WsHttpBinding 配置。试试这个(客户端必须使用相同的绑定配置):
The error says that you are sending HTTP request with content type which is not supported. Mentioned content type is used in SOAP 1.2 but BasicHttpBinding uses SOAP 1.1 with different content type (text/xml; charset=utf-8). So there is probably some mismatch between your service and client configuration.
In your second example the problem is default WsHttpBinidng configuration. WsHttpBinding is by default secured with message security and Windows authentication => exception because machines are in different domains so Windows auhtentication cannot work. You have to define your own WsHttpBinding configuration. Try this (same binding configuration has to be used on client):