c#调用delphi编写的SOAP Web Service(1)

c#如何调用delphi写的SOAP Web Service呢?

网上看到两种方法,

1、通过在Vistual Studio,增加web refrence的方式从wsdl引入wrapper,但是,总是报类型错误,开始怀疑可能是不支持某些特定类型,如olevariant。但仔细查看VS的警告信息,发现与wsdl中没有输出某些从TRemoteable继承下来的复杂类型有关。Delphi的wsdl只会输出那些在接口中直接使用到的复杂原件的定义,如果有多层继承,祖先没有直接被使用就不会输出。于是在接口中增加了几个不用的函数,把这些类别都用上。然后重新从VS汇入,“添加服务引用...”,成功。

但是调用的时候还是失败了,错误信息:

响应消息的内容类型 text/html; charset=iso-8859-1 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 541 个字节为:“<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>

我的SOAP Service安装在Apache中,设定调试参数为:-X -w -f "d:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf",关闭服务,在Delphi中运行,开始跟踪,

我Delphi XE版本15.0.3953.35171 ,跟踪发现在WebBrokerSoap.pas的这个地方出错:

function THTTPSoapDispatcher.DispatchRequest(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse): Boolean;
..............
              if IsMultiPart then
              begin
                BindingTypeIn := btMIME;
                MimeStream.ProcessMultiPartForm(ReqStream, XMLStream,
                         string(Request.ContentType), Nil,
                         Converter.Attachments, Converter.TempDir);
              end else
              begin
                { Load the SOAP Envelope directly into the XMLStream }
                BindingTypeIn := btSOAP;
                XMLStream.CopyFrom(ReqStream, 0);//这行报错“Stream read error”
              end;

继续跟踪到classes.pas的procedure TStream.ReadBuffer(var Buffer; Count: Longint);函数中,发现是它要读取371个字节,但是读到0个字节,所以报这个错。
为什么呢? 

用TCPTrace(http://www.pocketsoap.com/tcptrace/)工具看看C#传了些什么东西出来吧:

POST /TMTS/DCSoapServerBrokerIIS_Standalone.dll/soap/ISoapService HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo8jCedmtWQBDtUt1GRtNFUMAAAAAwwzVtxpxcEuCzmB2DZGPYO0IUNfw4PRNv2+9V5Cp2fEACQAA
SOAPAction: "urn:tmSoapInt-ISoapService#Test_Sum"
Host: localhost:8080
Content-Length: 372
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <q1:Test_Sum xmlns:q1="urn:tmSoapInt-ISoapService">
      <A xsi:type="xsd:int">3</A>
      <B xsi:type="xsd:int">4</B>
    </q1:Test_Sum>
  </s:Body>
</s:Envelope>

 如果在VS中用“添加web引用...”汇入wsdl,汇入也成功,但执行还是出错,TCPTrace截获的信息为:

POST /TMTS/DCSoapServerBrokerIIS_Standalone.dll/soap/ISoapService HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.261)
VsDebuggerCausalityData: uIDPo7B2LBy0PhlHmITzVeouookAAAAAb8BWzvTMh0SX09/DtaGIO38HgmbNMpxDgAxyODAZkEcACQAA
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:tmSoapInt-ISoapService#Test_Sum"
Host: localhost:8080
Content-Length: 564
Expect: 100-continue
Connection: Keep-Alive

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
  xmlns:tns="http://tempuri.org/" 
  xmlns:types="http://tempuri.org/encodedTypes" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <q1:Test_Sum xmlns:q1="urn:tmSoapInt-ISoapService">
      <A xsi:type="xsd:int">3</A>
      <B xsi:type="xsd:int">4</B>
    </q1:Test_Sum>
  </soap:Body>
</soap:Envelope>

 格式到底差在哪里呢?为什么Delphi的Web service就是不接受它呢?

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

火星牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值