Web services 从经典asp文件使用basicHttpBinding调用web服务
我有一个WCF web服务,它使用wsHttpBinding连接到大多数应用程序。我必须从一个经典的asp文件连接到此web服务。根据我的阅读和尝试,我需要使用basicHttpBinding来实现这一点。它是SOAP1.1,要使用webhttpbinding,我必须通过添加Web services 从经典asp文件使用basicHttpBinding调用web服务,web-services,soap,asp-classic,basichttpbinding,Web Services,Soap,Asp Classic,Basichttpbinding,我有一个WCF web服务,它使用wsHttpBinding连接到大多数应用程序。我必须从一个经典的asp文件连接到此web服务。根据我的阅读和尝试,我需要使用basicHttpBinding来实现这一点。它是SOAP1.1,要使用webhttpbinding,我必须通过添加[WebGet]来更改web服务接口,而这不是一个选项。因此,我将basicHttpBinding添加到web服务中 我使用控制台应用程序运行asp文件。当它运行时,我得到一个错误: 包含操作“urn:”的消息 由于Cont
[WebGet]
来更改web服务接口,而这不是一个选项。因此,我将basicHttpBinding添加到web服务中
我使用控制台应用程序运行asp文件。当它运行时,我得到一个错误:
包含操作“urn:”的消息
由于ContractFilter不匹配,无法在接收器上处理
在端点调度器。这可能是因为一份合同
不匹配(发送方和接收方之间的操作不匹配)或
发送方和接收方之间的绑定/安全不匹配。检查
发送方和接收方具有相同的合同和相同的约束力
(包括安全要求,例如消息、传输、无)
我看不出我错在哪里。我将URL设置为调用基本绑定。SOAP消息使用的是1.1,我相信它是正确的
为什么发送方和接收方之间存在不匹配?客户端上没有用于定义连接的app.config文件。它只是一个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>
这是如何在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
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"
'使用basicHttpBinding
URL=”http:///Fld1/PagingService.Paging.svc/basic"
'XML DOM对象。
Dim DOM、信封、正文、操作、参数
'创建一个XML DOM对象。
设置objXmlDoc=CreateObject(“MSXML2.DOMDocument.6.0”)
objXmlDoc.async=false
设置Envelope=objXmlDoc.createNode(1,“soap:Envelope”,NS_soap)
Envelope.setAttribute“xmlns:soapenc”,NS_soapenc
Envelope.setAttribute“xmlns:xsi”,nsxsi
Envelope.setAttribute“xmlns:xsd”,nsxsd
objXmlDoc.appendChild信封
Set Body=objXmlDoc.createNode(1,“Body”,“http://schemas.xmlsoap.org/soap/envelope/")
信封。子体
Set Operation=objXmlDoc.createNode(1,“TestMethod”,NS)
Body.appendChild操作
设置httpRequest=Server.CreateObject(“MSXML2.ServerXMLHTTP.6.0”)
httpRequest.Open“POST”,URL,False
httpRequest.setRequestHeader“内容类型”、“文本/xml”
httpRequest.setRequestHeader“SOAPAction”,“urn:http://tempuri.org/IPaging/TestMethod"
httpRequest.send objXmlDoc.xml
strStatusText=“状态:”&httpRequest.Status&vbCrLf&“状态文本:”&httpRequest.statusText
响应.写入(vbCrLf&strStatusText&vbCrLf)
Response.Write(httpRequest.responseText)
设置操作=无
集合体=无
设置信封=无
解决了这个问题。
从NS常量和SOAPAction字符串中删除了urn:
,它成功了
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