有人在使用Delphi与必应地图网络服务吗?

9
有人能够在Delphi中使用Bing地图Web服务(前身为Virtual Earth Web Services)吗?
根据我的经验(无论是使用Delphi还是Visual Studio C#),我都准备放弃并改用MapPoint Web服务,直到Bing Maps Web Services的未来版本发布。但是,作为最后一招,我想在这里发布一个问题...
我导入了令牌服务和地理编码服务的WSDL文档。
我成功地从令牌服务获取了令牌,但一直无法使地理编码服务正常工作。它总是返回以下错误消息: 由于EndpointDispatcher上的ContractFilter不匹配,因此无法处理Action''的消息接收器。这可能是由于发件人和收件人之间的合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全性不匹配引起的。请检查发件人和收件人是否具有相同的合同和相同的绑定(包括安全要求,例如Message、Transport、None)。
我注意到Delphi没有为SOAPAction头指定值,所以我尝试指定“http://staging.dev.virtualearth.net/webservices/v1/geocode/contracts/IGeocodeService/Geocode”,但却得到了以下错误消息:
服务器由于内部错误无法处理请求。有关错误的更多信息,请在服务器上打开IncludeExceptionDetailInFaults(从ServiceBehaviorAttribute或<serviceDebug>配置行为)以将异常信息发送回客户端,或者根据Microsoft .NET Framework 3.0 SDK文档打开跟踪并检查服务器跟踪日志。
下面是我的Delphi代码和发送的原始XML,然后是Microsoft示例C#代码的类似调用发送的原始XML。 XML中有几个差异,但我不确定哪些差异是关键。
var
  Service: IGeocodeService;
  Request: Geocode;
  Response: GeocodeResponse3;
  ResponseIndex: Integer;
  Token: WideString;
  Filters: ArrayOfFilterBase;
begin
  Token := GetToken;

  Service := GetIGeocodeService;

  Request := Geocode.Create;
  try
    Request.request := GeocodeRequest.Create;

    Request.request.Credentials := GeocodeService.Credentials.Create; // Freed by GeocodeRequest class
    Request.request.Credentials.Token := Token;

    Request.request.Query := AddressEdit.Text;

    Request.request.Options := GeocodeOptions.Create;

    SetLength( Filters, 1 );
    Filters[ 0 ] := ConfidenceFilter.Create;
    ConfidenceFilter( Filters[ 0 ] ).MinimumConfidence := GeocodeService.High_;

    Request.request.Options.Filters := Filters;

    Response := Service.Geocode( Request );
    try
      for ResponseIndex := Low( Response.GeocodeResult.Results ) to High( Response.GeocodeResult.Results ) do
      begin
        OutputMemo.Lines.Add( Response.GeocodeResult.Results[ ResponseIndex ].DisplayName );
      end;
    finally
      Response.Free;
    end;
  finally
    Request.Free;
  end;
end;


<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="http://dev.virtualearth.net/webservices/v1/geocode/contracts" xmlns:NS3="http://dev.virtualearth.net/webservices/v1/geocode" xmlns:NS4="http://dev.virtualearth.net/webservices/v1/common">
        <NS1:Geocode xmlns:NS1="http://dev.virtualearth.net/webservices/v1/geocode/contracts">
            <parameters href="#1"/>
        </NS1:Geocode>
        <NS2:Geocode id="1" xsi:type="NS2:Geocode">
            <request href="#2"/>
        </NS2:Geocode>
        <NS3:request id="2" xsi:type="NS3:GeocodeRequest">
            <Credentials href="#3"/>
            <Options href="#4"/>
            <Query xsi:type="xsd:string">Some Address</Query>
        </NS3:request>
        <NS4:Credentials id="3" xsi:type="NS4:Credentials">
            <Token xsi:type="xsd:string">cbYkKgNlrsGnZbn3HRP7Xp5LJMv3RR_5qECwgB792COfY3EPmviaDpZ4mmD3fDP1Osc6fWUkTptog7bfgM73bA2</Token>
        </NS4:Credentials>
        <NS3:Options id="4" xsi:type="NS3:GeocodeOptions">
            <Filters xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="NS3:FilterBase[1]">
                <item href="#5"/>
            </Filters>
        </NS3:Options>
        <NS3:ConfidenceFilter id="5" xsi:type="NS3:ConfidenceFilter">
            <MinimumConfidence xsi:type="NS4:Confidence">High</MinimumConfidence>
        </NS3:ConfidenceFilter>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <Geocode xmlns="http://dev.virtualearth.net/webservices/v1/geocode/contracts">
            <request xmlns:a="http://dev.virtualearth.net/webservices/v1/geocode" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <Credentials xmlns="http://dev.virtualearth.net/webservices/v1/common">
                    <ApplicationId i:nil="true"/>
                    <Token>pezCDpJoxdCG63NQdJUGkTrYYalnuSQDwuIC9FvheFAd9MIPO75qX9n7il0dx3eTEHlN2877PzN1_6YbQDL5tg2</Token>
                </Credentials>
                <Culture i:nil="true" xmlns="http://dev.virtualearth.net/webservices/v1/common"/>
                <ExecutionOptions i:nil="true" xmlns="http://dev.virtualearth.net/webservices/v1/common"/>
                <UserProfile i:nil="true" xmlns="http://dev.virtualearth.net/webservices/v1/common"/>
                <a:Address i:nil="true" xmlns:b="http://dev.virtualearth.net/webservices/v1/common"/>
                <a:Options>
                    <a:Count i:nil="true"/>
                    <a:Filters>
                        <a:FilterBase i:type="a:ConfidenceFilter">
                            <a:MinimumConfidence>High</a:MinimumConfidence>
                        </a:FilterBase>
                    </a:Filters>
                </a:Options>
                <a:Query>1 Microsoft Way, Redmond, WA</a:Query>
            </request>
        </Geocode>
    </s:Body>
</s:Envelope>
2个回答

3

我的最佳猜测是Delphi似乎生成了太多的Geocode元素 - 在C#生成的XML中没有任何与NS2: Geocode对应的内容。如果您可以拦截XML并更改它,使其看起来像这样,谁知道 - 它可能会起作用:

    ...
    <NS1:Geocode xmlns:NS1="http://dev.virtualearth.net/webservices/v1/geocode/contracts">
        <parameters href="#2"/>
    </NS1:Geocode>
    <NS3:request id="2" xsi:type="NS3:GeocodeRequest">
    ...

另一个问题可能是Bing服务不支持Delphi组织SOAP请求的方式。
如果这种方法行不通,也许你可以找到另一个可以与Delphi一起使用的SOAP库 - 也许可以使用带有C或COM接口的库进行封装。

谢谢,我之前尝试过类似的东西,但我刚刚再次尝试了一遍,没有成功。 - Nathan Sutcliffe

1

我有完全相同的问题。我运行 Delphi 2006,在命令模式下使用 WSDLImp.exe;需要使用 2006 版本11.0才能使导入工作正常。你使用什么版本?我们打算尝试 RemObjects,第6版。你觉得它会更好用吗?

祝好, Lars


我正在使用Delphi 2007。如果您在RemObjects方面有任何进展,我会非常感兴趣听到。我已经几周没有在这个项目上工作了,但我预计我们将继续使用旧的MapPoint API,直到Bing Map API成熟。 - Nathan Sutcliffe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接