使用经典asp文件

时间:2016-03-10 15:05:56

标签: web-services soap asp-classic basichttpbinding

我有一个使用wsHttpBinding连接到大多数应用程序的WCF Web服务。我必须从经典的asp文件连接到这个Web服务。根据我的阅读和尝试,我需要使用basicHttpBinding来做到这一点。它是SOAP 1.1并且要使用webhttpbinding,我必须通过添加[WebGet]来更改Web服务接口,这不是一个选项。所以我将basicHttpBinding添加到了Web服务中。

我使用控制台应用程序运行asp文件。当它运行时,我收到错误:

  

带有操作的消息' urn:http://tempuri.org/IPaging/TestMethod'   由于ContractFilter不匹配,无法在接收方处理   在EndpointDispatcher。这可能是因为合同   不匹配(发送者和接收者之间的不匹配行为)或a   发送方和接收方之间的绑定/安全性不匹配。校验   发件人和收件人具有相同的合同和相同的约束力   (包括安全要求,例如消息,传输,无)。

我不知道自己哪里出错了。我有URL设置来调用基本绑定。 SOAP消息使用1.1,我相信它是正确的。

为什么发送方和接收方之间存在不匹配? 客户端没有app.config文件来定义连接。它只是1个asp文件。如果我需要,asp文件如何读取app.config文件?

下面的配置文件:

<system.serviceModel>
<services>
  <service name="PagingService.Paging" behaviorConfiguration="SimpleServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPaging" contract="PagingService.IPaging">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPaging" contract="PagingService.IPaging">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/PagingService/Service1/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IPaging" maxReceivedMessageSize="20000000" maxBufferPoolSize="20000000" sendTimeout="00:25:00">
      <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
    </binding>
  </wsHttpBinding>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IPaging">
      <security mode="None"></security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="SimpleServiceBehavior">      
      <serviceMetadata httpGetEnabled="True"/>      
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>

我想从经典的asp文件中调用来自分页服务的方法TestMethod 这是描述TestMethod的WSDL:

<wsdl:operation name="TestMethod">
      <wsdl:input wsaw:Action="http://tempuri.org/IPaging/TestMethod" message="tns:IPaging_TestMethod_InputMessage" /> 
      <wsdl:output wsaw:Action="http://tempuri.org/IPaging/TestMethodResponse" message="tns:IPaging_TestMethod_OutputMessage" /> 
</wsdl:operation>

<wsdl:operation name="TestMethod">
  <soap:operation soapAction="http://tempuri.org/IPaging/TestMethod" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>

这是在WSDL中定义basicHttpBinding的方式:

<wsdl:port name="BasicHttpBinding_IPaging" binding="tns:BasicHttpBinding_IPaging">
<soap:address location="http://<server>:<port>/Fld1/PagingService.Paging.svc/basic" /> 
</wsdl:port>

这是调用Web服务的asp代码:

Dim NS, NS_SOAP, NS_SOAPENC, NS_XSI, NS_XSD
NS = "urn:http://tempuri.org/"
NS_SOAP = "http://schemas.xmlsoap.org/soap/envelope/"
NS_SOAPENC = "http://schemas.xmlsoap.org/soap/encoding"
NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
NS_XSD = "http://www.w3.org/2001/XMLSchema"

'Using basicHttpBinding
URL = "http://<server><port>/Fld1/PagingService.Paging.svc/basic"

' XML DOM objects.
Dim DOM, Envelope, Body, Operation, Param 

' Creates an XML DOM object.
Set objXmlDoc = CreateObject("MSXML2.DOMDocument.6.0") 
objXmlDoc.async = false

Set Envelope = objXmlDoc.createNode(1, "soap:Envelope", NS_SOAP)
Envelope.setAttribute "xmlns:soapenc", NS_SOAPENC
Envelope.setAttribute "xmlns:xsi", NS_XSI
Envelope.setAttribute "xmlns:xsd", NS_XSD
objXmlDoc.appendChild Envelope
Set Body = objXmlDoc.createNode(1, "Body", "http://schemas.xmlsoap.org/soap/envelope/")
Envelope.appendChild Body 
Set Operation = objXmlDoc.createNode(1, "TestMethod", NS)
Body.appendChild Operation 

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
httpRequest.Open "POST", URL, False    
httpRequest.setRequestHeader "Content-Type", "text/xml"  
httpRequest.setRequestHeader "SOAPAction", "urn:http://tempuri.org/IPaging/TestMethod"
httpRequest.send objXmlDoc.xml

strStatusText = "Status: " & httpRequest.status & vbCrLf & "Status text: " & httpRequest.statusText
Response.Write(vbCrLf & strStatusText & vbCrLf)  
Response.Write(httpRequest.responseText)

Set Operation = Nothing
Set Body = Nothing
Set Envelope = Nothing

1 个答案:

答案 0 :(得分:0)

想出来了。 从NS常量字符串和SOAPAction字符串中删除urn:并且它有效。