【问题标题】:Can't send WCF Service request as SOAP+XML无法将 WCF 服务请求作为 SOAP+XML 发送
【发布时间】:2011-05-31 11:08:44
【问题描述】:

使用 Visual Studio 2010,我开发了一个托管在 Web 应用程序上的 WCF 服务,供第三方使用。他们告诉我他们不能调用它。为了测试,他们将我重定向到 Altova XmlSpy 并指出,在创建新的 SOAP 请求时,如果他们在“更改 SOAP 请求参数”菜单项中选择“作为 SOAP+XML (SOAP 1.2) 发送”,他们会得到以下两个警报对话框:

HTTP error: could not POST file ‘/TurniArc/WebServices/Processi.svc’ on server ’10.51.0.108’ (415)

Error sending the soap data to ‘http://10.51.0.108/TurniArc/WebServices/Processi.svc’ HTTP error: could not POST file ‘/TurniArc/WebServices/Processi.svc’ on server ’10.51.0.108’ (415)

我确实证实了这一点。 取消选中该选项,请求将根据需要提交。而且我在使用我一直用于内部测试的软件 soapUI 调用我的 Web 服务时从来没有遇到任何问题。

这是我创建的第一个 Web 服务,从没有任何理论知识开始(但我想每个人都这样做:-)),所以我什至不知道在哪里解决这个问题。问题可能出在绑定上吗?我使用 Add/New Item/WCF Service 创建了服务,并保留了所有默认选项,所以它应该是 BasicHttpBinding

这是我的 web.config 的 serviceModel 部分

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<!--other bindings related to proxies to other services I'm invoking -->
</system.serviceModel>

我的界面只有

[ServiceContract(Namespace="http://www.archinet.it/HRSuite/Processi/")]

属性和实现它的类具有

[ServiceBehavior(IncludeExceptionDetailInFaults = true, Namespace = "http://www.archinet.it/HRSuite/Processi/")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

属性

谢谢

编辑:第三方正在使用 Oracle SOA 中间件

【问题讨论】:

    标签: c# wcf soap xmlspy


    【解决方案1】:

    BasicHttpBinding 使用 SOAP 1.1,因此您无法使用此绑定将 SOAP 1.2 中的请求发送到端点。 HTTP 状态码 415 表示不受支持的媒体类型,这也暗示了这一点,因为 SOAP 1.1 使用 text/xml 内容类型,而 SOAP 1.2 使用 application/soap+xml 内容类型。

    如果您希望 BasicHttpBinding 与 SOAP 1.2 等效,而 WsHttpBinding 中不包含任何其他 WS-* 内容,则需要创建自定义绑定。最简单的版本如下:

    <bindings>
      <customBinding>
        <binding name="soap12">
          <textMessageEncoding messageVersion="Soap12" />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    

    然后您必须手动为您的服务定义端点(此时您正在使用默认端点):

    <services>
      <service name="YourNamespace.YourServiceClass">
        <endpoint address="" binding="customBinding" bindingConfiguration="soap12" 
                  contract="YourNamespace.YourServiceContractInterface" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    

    无论如何,我几乎不相信重新配置 SOAP 版本以在 Oracle SOA 中间件中使用您的服务需要几分钟的时间。

    【讨论】:

    • 正如我刚刚在消息中所写的,他们使用的是 Oracle SOA,因此,只要他们可以更改请求格式,他们必须进行的每一个小编辑都是一件漫长而繁重的事情。由于我这边比较敏捷,所以我想对齐我的软件;我今天早上研究了一下,wsHttpBinding 总体上看起来更好。是吗?
    • “我几乎不相信在 Oracle SOA 中间件中重新配置 SOAP 版本以使用您的服务需要几分钟的时间。”好吧,过去他们告诉我,每次更新都必须重新部署所有内容,而且总是需要几天时间!不管怎样,我马上试试你的代码,谢谢
    • 完全相同的错误可能意味着您的配置未被使用。尝试在配置中犯一些错误 - 例如不存在的合同。
    • 我设置了 messageVersion = "Soap122" 并在尝试在浏览器中打开服务 url 时得到了The value of the property 'messageVersion' cannot be parsed. The error is: The value 'Soap122' is not a valid instance of type 'System.ServiceModel.Channels.MessageVersion'. Parameter name: value ,所以恐怕情况并非如此。显然 XmlSpy 和 soapUI 都不能创建它们的代理
    • 您能否在 wsdl 或 soapUI 中验证该服务确实公开了 soap 1.2 端点?
    猜你喜欢
    • 1970-01-01
    • 2012-03-18
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多