繁体   English   中英

WCF 3.5-具有不同绑定和SOAP的不同端点

[英]Wcf 3.5 - Different endpoints with different bindings and SOAP

我有问题...我浏览了整个互联网,但我不知道自己在做什么错。

问题: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与自定义客户端,但无法找到正在发生的情况

有什么建议或建议吗?

谢谢你的时间

编辑:

启用S​​vc跟踪后,我遇到了几个异常:

<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;
}

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

通常,这是非常糟糕的做法-不应以这种方式手动将SOAP请求创作到WCF服务。 如果您要利用现成的WCF请求/答复范例而不是手动设置标头,则更好。

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

另外,仅凭提供的细节很难分辨出您可能还会做错什么。

这是我的建议:

通常,一旦执行此操作,您就应该在服务端获取更多有关时髦问题的信息,并且可以很快地诊断出问题。 试试看,请回报! :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM