请高手分析下WebService有返回值,但返回值总是同一个的问题

qingzhiyun 2018-06-11 07:04:38
上次提问的帖子
https://bbs.csdn.net/topics/392395664

——————————————————————
hj8090:

按照你说的改了,有了返回值,但不管发送什么字符串返回都是一样的({"obj":"003"})

但我用测试工具发送{"token":"14123ss23sf3oodhgl38403","msgType":"10001","msgBody":{"manifestNo":"20180923004","plateNumber":"晋AB0322","driverName":"张无忌","driverIdentityCardNo":"132305198907050043"}} 返回值为( {"obj":"004"} )

测试工具信息如下:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 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>
<process xmlns="http://api.weighbridge.internet.shencai.com/">
<arg0 xmlns="">{"token":"14123ss23sf3oodhgl38403","msgType":"10001","msgBody":{"manifestNo":"20180923004","plateNumber":"晋AB0322","driverName":"张无忌","driverIdentityCardNo":"132305198907050043"}}</arg0>
</process>
</soap:Body>
</soap:Envelope>

——————————————————————————

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:processResponse xmlns:ns2="http://api.weighbridge.internet.shencai.com/">
<return>{"obj":"004"}</return>
</ns2:processResponse>
</soap:Body>
</soap:Envelope>
...全文
1326 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hj8090 2018-06-13
  • 打赏
  • 举报
回复
1如果服务端是你自己的,可以比较下Delphi发送的参数和其他语言发送的参数有什么区别? 2用高版本的Delphi重新导入这个wsdl,我只有XE3,导入没有成功。 3用C#测试是{"obj":"004"}
lyhoo163 2018-06-13
  • 打赏
  • 举报
回复
Delphi Web 就是问题不少。
qingzhiyun 2018-06-13
  • 打赏
  • 举报
回复
看来的是delphi的问题了,服务端不是自己的,没法。
qingzhiyun 2018-06-12
  • 打赏
  • 举报
回复
重新再delphi2010中做了客户端,返回值都是{"obj":"003"},怀疑是客户端接收为null造成,因为发送有效字符还是无效字符都返回{"obj":"003"},返回代码标识格式错误。 用测试工具发送有效字符串返回{"obj":"004"}。
SolidWasteService单元,delphi生成。
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://211.90.38.54:18282/WebService/SolidWasteService?wsdl
//  >Import : http://211.90.38.54:18282/WebService/SolidWasteService?wsdl=ISolidWasteService.wsdl
//  >Import : http://211.90.38.54:18282/WebService/SolidWasteService?wsdl=ISolidWasteService.wsdl>0
// Encoding : UTF-8
// Version  : 1.0
// (2018-06-11 20:09:19 - - $Rev: 25127 $)
// ************************************************************************ //

unit SolidWasteService;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

const
  IS_OPTN = $0001;
  IS_UNQL = $0008;


type

  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Embarcadero types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:string          - "http://www.w3.org/2001/XMLSchema"[Gbl]



  // ************************************************************************ //
  // Namespace : http://api.weighbridge.internet.shencai.com/
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // binding   : SolidWasteServiceImplServiceSoapBinding
  // service   : SolidWasteServiceImplService
  // port      : SolidWasteServiceImplPort
  // URL       : http://211.90.38.54:18282/WebService/SolidWasteService
  // ************************************************************************ //
  ISolidWasteService = interface(IInvokable)
  ['{4C6FB50E-23F9-5664-0A8D-F79439A6E7E1}']
    function  process(const arg0: string): string; stdcall;
  end;

function GetISolidWasteService(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ISolidWasteService;


implementation
  uses SysUtils;

function GetISolidWasteService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ISolidWasteService;
const
  defWSDL = 'http://211.90.38.54:18282/WebService/SolidWasteService?wsdl';
  defURL  = 'http://211.90.38.54:18282/WebService/SolidWasteService';
  defSvc  = 'SolidWasteServiceImplService';
  defPrt  = 'SolidWasteServiceImplPort';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as ISolidWasteService);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;


initialization
  InvRegistry.RegisterInterface(TypeInfo(ISolidWasteService), 'http://api.weighbridge.internet.shencai.com/', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ISolidWasteService), '');
  InvRegistry.RegisterInvokeOptions(TypeInfo(ISolidWasteService), ioDocument);
  //InvRegistry.RegisterInvokeOptions(TypeInfo(ISolidWasteService), ioLiteral);
end.
客户端代码
unit weight;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, InvokeRegistry, Rio, SOAPHTTPClient, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    HTTPRIO1: THTTPRIO;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses SolidWasteService;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
tmp_p: String;
tmp_r :string;
begin
tmp_p:='{"token":"14123s","msgType":"10001","msgBody":{"manifestNo":"201804","plateNumber":"晋AB322","driverName":"张","driverIdentityCardNo":"132305198907050043"}}';
tmp_r:=GetISolidWasteService(false,'',nil).process(tmp_p);
Memo2.Lines.Text:=tmp_r;

end;

end.
用测试工具测试'{"token":"14123s","msgType":"10001","msgBody":{"manifestNo":"201804","plateNumber":"晋AB322","driverName":"张","driverIdentityCardNo":"132305198907050043"}}';返回值为{"obj":"004"}
表单
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 443
  ClientWidth = 606
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 240
    Top = 128
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo2: TMemo
    Left = 288
    Top = 288
    Width = 185
    Height = 89
    ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
    Lines.Strings = (
      'Memo2')
    TabOrder = 1
  end
  object HTTPRIO1: THTTPRIO
    URL = 'http://211.90.38.54:18282/WebService/SolidWasteService?wsdl'
    HTTPWebNode.UseUTF8InHeader = True
    HTTPWebNode.InvokeOptions = [soIgnoreInvalidCerts, soAutoCheckAccessPointViaUDDI]
    HTTPWebNode.WebNodeOptions = []
    Converter.Options = [soSendMultiRefObj, soTryAllSchema, soRootRefNodesToBody, soCacheMimeResponse, soUTF8EncodeXML]
    Left = 216
    Top = 224
  end
end
pzx521521 2018-06-12
  • 打赏
  • 举报
回复
不要用delphi 做web了 看了就头疼..... php java go python 那个做web不比delphi 强 前两天用delphi的idhttp调做好的接口都有问题 post数据中 "+"号 在java后台那里被urldecode为空格 死活找不到原因 最后idhttp换系统原生的IXMLHTTPRequest 搞定
天行归来 2018-06-12
  • 打赏
  • 举报
回复
用RestClient做了个测试,发现msgType值不同,返回 json obj 的值也不同,接口调用应该是正常,你应该先获取到webservice各类返回值对应含义。再检查参数是否有正确。 在不知道参数有效值以及返回代码含义情况下,等于瞎子摸象。

比如:msgType="1000"  <return>{"obj":"003"}</return>
            msgType="1001"  <return>{"obj":"004"}</return>
qingzhiyun 2018-06-11
  • 打赏
  • 举报
回复
客户端代码
procedure TForm1.Button3Click(Sender: TObject);
var
tmp_p: process;
tmp_r :Widestring;
begin
//HTTPRIO1.HTTPWebNode.UseUTF8InHeader :=True;
tmp_p:=process.Create ;
//tmp_r:=processResponse.Create;
tmp_p.arg0:=WidestringToString(Memo1.Lines.Text);
tmp_r:=GetSolidWasteService(False,'',HTTPRIO1).process(tmp_p);
//Memo2.Lines.Text:=tmp_r.return;
Memo2.Lines.Text:=(tmp_r) ;
end;
哪里出现问题了呢?

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧