我要调用以下WEBSERVICE:
http://192.168.0.222:82/addressbookWS/AddressbookService.asmx?op=UserAddContactGroup,下边是调用的请求示例
POST /addressbookWS/AddressbookService.asmx HTTP/1.1
Host: 192.168.0.222
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/UserAddContactGroup"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <UserAddContactGroup xmlns="http://tempuri.org/">
      <UserName>string</UserName>
      <UserPass>string</UserPass>
      <GroupName>string</GroupName>
      <GroupDesc>string</GroupDesc>
    </UserAddContactGroup>
  </soap:Body>
</soap:Envelope>
代码如下:
const CString wsURL="http://192.168.0.222:82/addressbookWS/AddressbookService.asmx?WSDL";
ISoapSerializerPtr Serializer;
    ISoapReaderPtr Reader;
    ISoapConnectorPtr Connector;
    try
{
HRESULT hr;
bool m_bLocal = false;
hr= CoInitialize(NULL);//初始化com环境
if(FAILED(hr))
{
AfxMessageBox("初始化COM失败");
return;
}
         hr = Connector.CreateInstance(__uuidof(HttpConnector30));
CHECK_HR(hr);
Connector->Property["EndPointURL"] =(LPTSTR)(LPCTSTR)wsURL;// "http://MyServer/Soap3DocSamples/DocSample1/Server/DocSample1.wsdl";
Connector->Connect();
          Connector->Property["SoapAction"] ="http://tempuri.org/UserAddContactGroup";//"http://tempuri.org/DocSample1/action/Sample1.AddNumbers";
   Connector->BeginMessage();    // Create the SoapSerializer object.
   Serializer.CreateInstance(__uuidof(SoapSerializer30));    // Connect the serializer object to the input stream of the connector object.
   Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

   // Build the SOAP Message.
   Serializer->StartEnvelope("SOAP", "http://schemas.xmlsoap.org/soap/envelope/", "");
    Serializer->SoapAttribute("xsi", "","http://www.w3.org/2001/XMLSchema-instance","xmlns");
Serializer->SoapAttribute("xsd","","http://www.w3.org/2001/XMLSchema","xmlns");
   Serializer->StartBody(L"NONE");
   Serializer->StartElement("UserAddContactGroup","AddressBook","","");
// Serializer->StartElement("username","","","");
   Serializer->StartElement("UserName","","","");
   Serializer->SoapAttribute("xsi:type", "", "xsd:string", "");
   Serializer->WriteString("88040000");
   Serializer->EndElement();    Serializer->StartElement("UserPass","","","");
   Serializer->WriteString("88040000");
   Serializer->WriteString("111111");
   Serializer->EndElement();
   Serializer->StartElement("GroupName","","","");
   Serializer->WriteString("88040000");
   Serializer->WriteString("联系人");
   Serializer->EndElement();
   Serializer->StartElement("GroupDesc","","","");
   Serializer->WriteString("88040000");
   Serializer->WriteString("创建的联系人");
   Serializer->EndElement();
          Serializer->EndElement();   Serializer->EndBody();   Serializer->EndEnvelope();
   
   // Send the message to the XML Web service.
   Connector->EndMessage();         // Read the response.
   Reader.CreateInstance(__uuidof(SoapReader30));   // Connect the reader to the output stream of the connector object.
   Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");   // Display the result.
   CString msg;
   msg.Format("Answer: %s\n", (const char*)Reader->RpcResult->xml);
AfxMessageBox(msg);
   //在调用了以上的代码后,返回的是SOAP:Server,不知什么原因,请帮帮忙

解决方案 »

  1.   

    如果使用VC的话,建议直接使用“web 应用”
    ms给封装的非常好。soaptookit在打包方面,存在很多问题。
      

  2.   

    呵呵,我用VC6,好象没有引用WEB应用这个东东吧
      

  3.   

    我用的是VC6+SOAP3,最上边的示例是.NET开发的WEBSERVICE提供的访问示例,而我发的包如下:
    POST /addressbookWS/AddressbookService.asmx?WSDL HTTP/1.1..
    SOAPAction: "http://tempuri.org/UserAddContactGroup"..
    Content-Type: text/xml; charset="UTF-8"..User-Agent: 
    SOAPToolkit 3.0..Host: 192.168.0.222:82..
    Content-Length: 874..
    Connection: Keep-Alive..
    Cache-Control: no-cache..
    Pragma: no-cache...
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <SOAP:Envelope
     SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:
    SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:
    SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:
    SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:
    xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:
    xsd="http://www.w3.org/2001/XMLSchema"><SOAP:Body>
    <SOAPSDK4:UserAddContactGroup xmlns:SOAPSDK4="AddressBook" SOAP:encodingStyle="">
    <UserName SOAP:encodingStyle="" xsi:type="xsd:string">88040000</UserName>
    <UserPass SOAP:encodingStyle="">111111</UserPass>
    <GroupName SOAP:encodingStyle="">.........</GroupName>
    <GroupDesc SOAP:encodingStyle="">........................</GroupDesc>
    </SOAPSDK4:UserAddContactGroup></SOAP:Body></SOAP:Envelope>