调用webservice出错

diablobaal 2015-07-20 01:55:17
连接webservice后生成的模块代码如下:
unit DataTransmissionService1;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

type

DataTransmissionService = interface(IInvokable)
['{5BAC4FD9-8B6F-C20F-1765-14E0CCFB7CFC}']
function transportEnergyData(const buildingid:WideString;const gatewayid:WideString;const sequence:WideString;const md5:WideString;const mymessage:WideString): WideString; stdcall;
function transportHeartBeat(const buildingid:WideString;const gatewayid:WideString): WideString; stdcall;
end;
function GetDataTransmissionService(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): DataTransmissionService;


implementation

function GetDataTransmissionService(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): DataTransmissionService;
const
defWSDL = 'http://data.yangpufxjl.org:9000/DataTransmissionService?WSDL';
defURL = 'http://data.yangpufxjl.org:9000/DataTransmissionService';
defSvc = 'DataTransmissionService';
defPrt = 'DataTransmissionServicePort';
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 DataTransmissionService);
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(DataTransmissionService), 'http://platform.ems.jky/', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(DataTransmissionService), '');
InvRegistry.RegisterInvokeOptions(TypeInfo(DataTransmissionService), ioDocument);
InvRegistry.RegisterInvokeOptions(TypeInfo(DataTransmissionService), ioLiteral);

end.
调用代码如下:
var
sendstring:string;//要发送的数据包
mysend:DataTransmissionService;//webservice的服务器定义
md5:string;
begin
mysend:=GetDataTransmissionService(False,'',nil);
md5:=model.MD5Ecryption(AuthenticationKey+sequence);
sendstring:=mysend.transportHeartBeat(building_id,gateway_id);
end;

报错如下:
cannot find dispatch method for
{http://schemas.xmlsoap.org/soap/envelope/}string


是服务器没连上吗,第一次做webservice,真心不懂,望各位高手指点
...全文
725 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
缘中人 2015-08-17
  • 打赏
  • 举报
回复
Indy10这下你研究清楚了
diablobaal 2015-08-13
  • 打赏
  • 举报
回复
终于解决了,返回能是16进制数,代码要改成: { 函数名称:MD5Ecryption 函数功能:生成MD5加密字符串 indy10的写法 适合2010 函数参数: source 要加密的字符串 } function MD5Ecryption(source:String):tbytes;//MD5加密 var Md5Encode: TIdHashMessageDigest5; begin Md5Encode:= TIdHashMessageDigest5.Create; try //Result := Md5Encode.AsHex(Md5Encode.HashValue(S)); // Indy9的写法 //Result := Md5Encode.HashStringAsHex(source,TEncoding.UTF8); // Indy10中可以直接HashStringAsHex ,返回16进制数 Result := Md5Encode.HashString(source,TEncoding.UTF8); // Indy10中可以直接HashStringAsHex ,返回byte字符串 finally Md5Encode.Free; end; end;
diablobaal 2015-07-31
  • 打赏
  • 举报
回复
我和做服务器的人对过md5了,没错,但就是发过去不认,我也是醉了
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
他给的java例子的md5函数我这里没有,我是自己做的 还有InvRegistry.RegisterInvokeOptions(TypeInfo(DataTransmissionService), ioDocument);这句不能加,加上就报错,不加上心跳包返回就正确
缘中人 2015-07-30
  • 打赏
  • 举报
回复
public byte[] getMd5(byte[] secretCode,byte[] sequence) throws NoSuchAlgorithmException{
byte[] content=new byte[secretCode.length+sequence.length];

System.arraycopy(secretCode, 0, content, 0, secretCode.length);
System.arraycopy(sequence, 0, content, secretCode.length, sequence.length);

byte[] md5=Secret.getMd5(content);
return md5;
}
Function getMd5(secretCode:TByteDynArray;sequence:TByteDynArray):TByteDynArray;
var
  content:TByteDynArray;
  temp:ansistring;
begin
  SetLength(content,length(secretCode)+length(sequence));
  Move(secretCode[0], content[0], length(secretCode));
  Move(sequence[0], content[length(secretCode)+1], length(sequence));
  SetLength(temp, Length(content));
  move(content[0],temp[1],Length(content));
  result:=stringtoTByteDynArray(MD5Ecryption(temp));
end;
缘中人 2015-07-30
  • 打赏
  • 举报
回复
问题就出在getMd5函数上了?他这是自定义的吗,指定密钥的md5?
yuxuan0102 2015-07-30
  • 打赏
  • 举报
回复
ILisSoap 改成你的 DataTransmissionService
缘中人 2015-07-30
  • 打赏
  • 举报
回复
buildingId, gagewayId, sequenceBytes,md5, msg 4个参数,是不是msg有问题
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
initialization InvRegistry.RegisterInterface(TypeInfo(DataTransmissionService), 'http://platform.ems.jky/', 'UTF-8'); InvRegistry.RegisterDefaultSOAPAction(TypeInfo(DataTransmissionService), ''); //InvRegistry.RegisterInvokeOptions(TypeInfo(DataTransmissionService), ioDocument); InvRegistry.RegisterExternalParamName(TypeInfo(ILisSoap), 'queryInterface', 'function_', 'function');
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
ILisSoap 没定义
yuxuan0102 2015-07-30
  • 打赏
  • 举报
回复
initialization 下面添加 InvRegistry.RegisterExternalParamName(TypeInfo(ILisSoap), 'queryInterface', 'function_', 'function');
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
他提供的java例子如下:package test; import java.io.File; import java.io.UnsupportedEncodingException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import org.dom4j.Document; import org.dom4j.io.SAXReader; import jky.ems.platform.Secret; public class TestDatatransmissionService { /** * @param args * @throws NoSuchAlgorithmException */ public byte[] getMd5(byte[] secretCode,byte[] sequence) throws NoSuchAlgorithmException{ byte[] content=new byte[secretCode.length+sequence.length]; System.arraycopy(secretCode, 0, content, 0, secretCode.length); System.arraycopy(sequence, 0, content, secretCode.length, sequence.length); byte[] md5=Secret.getMd5(content); return md5; } public void testDataTransmisissionWebservice(byte[] sequenceBytes,byte[] keywordBytes,String xml,String buildingId,String gagewayId) throws Exception{ DataTransmissionService_Service service=new DataTransmissionService_Service(); DataTransmissionService dtService =service.getDataTransmissionServicePort(); byte[] md5=getMd5(keywordBytes, sequenceBytes); byte[] msg=Secret.encryptAES(xml.getBytes("UTF-8"), keywordBytes); String reponse=dtService.transportEnergyData(buildingId, gagewayId, sequenceBytes,md5, msg); System.out.println(reponse); } public void testHeatWebService(String buildingId,String gagewayId){ DataTransmissionService_Service service=new DataTransmissionService_Service(); DataTransmissionService dtService =service.getDataTransmissionServicePort(); String msg=dtService.transportHeartBeat(buildingId,gagewayId); System.out.println(msg); } public static void main(String[] args) throws Exception, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException { Secret.init(); // TODO Auto-generated method stub String sequence="467675s"; String keyword="32804FAB4E944C79";//23e67e172fe044c8 String buildingId="310112B003"; String gagewayId="gateway1"; byte[] sequenceBytes=sequence.getBytes("UTF-8"); byte[] keywordBytes=keyword.getBytes("UTF-8"); String fileName; if(args.length>0){ fileName=args[0]; buildingId=args[1]; keyword=args[2]; System.out.println("fileName="+fileName); System.out.println("buildingId="+buildingId); System.out.println("keyword="+keyword); }else{ fileName="d:/UP02.xml"; } File xmlFile=new File(fileName); SAXReader reader=new SAXReader(); Document xmlDoc=reader.read(xmlFile); String xml=xmlDoc.asXML(); TestDatatransmissionService test=new TestDatatransmissionService(); test.testDataTransmisissionWebservice(sequenceBytes, keywordBytes, xml, buildingId,gagewayId); test.testHeatWebService(buildingId, gagewayId); } } java我用不太来
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
md5 我验证过,是根据他提供的例子验证的,abc md5是900150983cd24fb0d6963f7d28e17f72 一点问题没有 他给的楼宇代码:YP310110BG0073 密钥:23e67e172fe044c8 我要疯了
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
不行啊,我试了好几天,晕死了
缘中人 2015-07-30
  • 打赏
  • 举报
回复
MD5, ansiString和Unicode 两种。他都不能识别?
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
只是调用getMd5函数 哪里md5又套getMd5?
diablobaal 2015-07-30
  • 打赏
  • 举报
回复
2010可以 就是把密钥和随机序列连接后转成byte数组,然后计算md5,然后把md5值再转成byte数组后发送
缘中人 2015-07-29
  • 打赏
  • 举报
回复
md5又套getMd5?
缘中人 2015-07-29
  • 打赏
  • 举报
回复
2010可以?xe8 都不行
diablobaal 2015-07-29
  • 打赏
  • 举报
回复
找到原因了,delphi7不行,用2010可以了,心跳包返回正确,但是出现个新问题,服务器返回提示md5 is error,但我的md5验证过是对的,请高手指教。代码如下: var fwq:string;//服务器的返回参数 sendstring:string;//要发送的数据包 temp:array of Tarray;//临时数组 i,j,k:Integer;//循环变量 myday:TsystemTime; mym:integer; mysend:DataTransmissionService;//webservice的服务器定义 temp1,temp2,temp3,temp4:TByteDynArray;//临时数组 begin try sendstring:=''; fwq:=''; SetLength(temp,20,3); temp1:=stringtoTByteDynArray(ToUTF8Encode(AuthenticationKey)); temp2:=stringtoTByteDynArray(ToUTF8Encode(sequence)); temp3:=getMd5(temp1,temp2); mysend:=GetDataTransmissionService(False,'',nil); temp4:=stringtoTByteDynArray('abc'); sendstring:= mysend.transportEnergyData(building_id,gateway_id,temp2,temp3,temp4); mmo1.Lines.Add(sendstring); AuthenticationKey为密钥 sequence为随机序列 这都没问题 ToUTF8Encode函数如下: function ToUTF8Encode(str: ansistring): ansistring; var u:UTF8String; begin u:=AnsiToUTF8(str); result:=u; end; 加密函数如下: function MD5Ecryption(source:String):String;//MD5加密 var Md5Encode: TIdHashMessageDigest5; begin Md5Encode:= TIdHashMessageDigest5.Create; try //Result := Md5Encode.AsHex(Md5Encode.HashValue(S)); // Indy9的写法 Result := Md5Encode.HashStringAsHex(source,TEncoding.UTF8); // Indy10中可以直接HashStringAsHex finally Md5Encode.Free; end; end; getMd5函数: Function getMd5(secretCode:TByteDynArray;sequence:TByteDynArray):TByteDynArray; var content:TByteDynArray; temp:ansistring; begin SetLength(content,length(secretCode)+length(sequence)); Move(secretCode[0], content[0], length(secretCode)); Move(sequence[0], content[length(secretCode)+1], length(sequence)); SetLength(temp, Length(content)); move(content[0],temp[1],Length(content)); result:=stringtoTByteDynArray(MD5Ecryption(temp)); end; TByteDynArray类型的定义就是array of byte
加载更多回复(13)

1,593

社区成员

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

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