【问题标题】:Wcf 3.5 - Different endpoints with different bindings and SOAPWcf 3.5 - 具有不同绑定和 SOAP 的不同端点
【发布时间】:2012-04-26 23:35:30
【问题描述】:

我有一个问题...我探索了整个互联网,但我不知道我做错了什么。

问题:WCF Web 服务、.Net Framework 3.5、2 种不同类型的客户端(手持设备和普通计算机)

我要做的是创建 2 个不同的端点,一个带有 basicBinding(用于 SOAP 请求),另一个带有 wsBinding(用于普通计算机)

所以我通过 web.config 创建了 2 个不同的绑定,与 2 个不同的端点相关:

<bindings>
  <basicHttpBinding>
    <binding name="BasicBinding" openTimeout="00:10:00" receiveTimeout="23:59:00"
      sendTimeout="23:59:00" messageEncoding="Text" />
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="DefaultBinding" openTimeout="00:10:00" receiveTimeout="23:59:59"
      sendTimeout="23:59:59">
      <reliableSession inactivityTimeout="01:00:00" />
      <security mode="None">
        <transport clientCredentialType="None" />
        <message clientCredentialType="None" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="qtswsdl.QTS_ServiceBehavior"
    name="qtswsdl.QTS_Service">
    <endpoint address="http://host.com/service.svc/ForHh"
      binding="basicHttpBinding" bindingConfiguration="BasicBinding"
      name="handHeldEndPoint" contract="qtswsdl.QTSPort" />
    <endpoint address="http://host.com/service.svc/ForCp"
      binding="wsHttpBinding" bindingConfiguration="DefaultBinding"
      name="coProcessorEndPoint" contract="qtswsdl.QTSPort" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="qtswsdl.QTS_ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <serviceThrottling maxConcurrentCalls="2147483647"maxConcurrentSessions="2147483647"
        maxConcurrentInstances="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

因此,当我尝试将 SOAP 消息发送到“http://host.com/service.svc/ForHh”时,我收到“HTTP 400 - 错误请求”(/ForCp 也不起作用)

我尝试使用自定义客户端,使用 WcfTestClient.exe,但无法确定发生了什么

有什么提示或建议吗?

感谢您的宝贵时间

编辑:

启用 Svc 跟踪后,我遇到了一些异常:

<Message>The message with Action 'http://Host.com/Service.svc/ForHh' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</Message>

有趣的是,我正在以编程方式发送 SOAP 请求。我的理解是,如果我以编程方式发送 SOAP 请求,我不需要定义任何合同,因为默认情况下它是使用 SOAP 1.1 发送的。

发送请求的代码如下:

private string SendRequestAndGetAnswerFromWebService(string methodName, string requestXml){

     StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
                soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
                soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
                soapRequest.Append(requestXml);//Body
                soapRequest.Append("</soap:Body></soap:Envelope>");

                   WebRequest webRequest = WebRequest.Create(@"http://Host.com/Service.svc/" + methodName);
                   HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
                   httpRequest.Method = "POST";
                   httpRequest.ContentType = "text/xml; charset=ascii";
                   httpRequest.Headers.Add("SOAPAction: " + @"http://Host.com/Service.svc/Service.svc/" + methodName);
                   httpRequest.ProtocolVersion = HttpVersion.Version11;
                   httpRequest.Credentials = CredentialCache.DefaultCredentials;
                   httpRequest.Timeout = 7000;
                   httpRequest.ContentLength = System.Text.Encoding.ASCII.GetByteCount(soapRequest.ToString());
                   Stream requestStream = httpRequest.GetRequestStream();

                   //Create Stream and send Request 
                   StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);
                   streamWriter.Write(soapRequest.ToString());
                   //Send the request             
                   streamWriter.Close();

                   //Get the Response
                   HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
                   StreamReader srd = new StreamReader(wr.GetResponseStream());
                   string resulXmlFromWebService = srd.ReadToEnd();
                   return resulXmlFromWebService;
}

也许我对以编程方式发送的合同和肥皂消息的假设是错误的......

【问题讨论】:

  • 打开 wcf 跟踪并得到确切的错误:blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx
  • 已编辑。谢谢你们的时间
  • 皂化头似乎是错误的。您可以在 wsdl 中看到正确的。
  • 是的,抱歉,在“真实”代码中它是正确的。是我的错,因为我想“隐藏”真实的网址。你可以相信这一点。关于以编程方式发送 SOAP 请求......我的假设是否正确?我的意思是,我不需要客户端的任何合同。谢谢你的时间亚龙
  • 我建议您现在专注于使用 wcf 测试客户端。也许创建一些新服务只是为了检查它是否有效,然后将工作服务配置与您的进行比较

标签: wcf soap


【解决方案1】:

一般来说,这是一种非常糟糕的做法——您不应该以这种方式手动编写对 WCF 服务的 SOAP 请求。如果您要利用开箱即用的 WCF 请求/回复范例而不是手动设置标头,那就更好了。

我建议创建一个替代示例,您可以在其中实现开箱即用的相同功能(可能在客户端使用 DataContracts、OperationContracts 和 ServiceContracts,可能利用 WebHttpBehavior 和 WebHttpBinding) .检查在该场景中发送和接收的确切消息,并逐个字符仔细检查这些消息与您在此处发送的消息有何不同。

此外,仅从您提供的详细信息很难判断您可能做错了什么。

这是我的建议:

一般来说,一旦你这样做了,你应该得到更多关于服务端出现问题的更多信息,并且可以很快诊断出问题。试试看,请回来报告! :)

【讨论】:

  • 感谢您的建议。让我们试试吧
  • 抱歉耽搁了。您的建议让我注意到了真正的问题。肥皂消息没有需要的值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-09
  • 2011-04-25
相关资源
最近更新 更多