pb9生成webservice对象如何改服务地址
开发时webservice对象建立后deploy后调用
但开发时的webservice服务地址与实际应用地址并不一致,移植也同样存在上述问题
有没有办法直接修改web服务地址,或者把服务地址做成参数调用
现在用的是pb9,据说pb11的createinstance函数具有地址参数
[解决办法]
pb12 里面可以通过 SetProxyServer() 指定服务器地址和端口;通过 SetOption() 指定超时等待时间。
[解决办法]
conn.CreateInstance (ref powerobject proxy_obj, string proxy_name, {string portname}) throws SoapException
ArgumentDescription
connThe name of the SoapConnection object that establishes the connection
proxy_objThe referenced name of your proxy object
proxy_nameThe name of the proxy, based on the port name from a URL in the WSDL file stored in the proxy
portname (Optional) The port name from a URL not stored in the proxy
第三个参数portname就是你实际使用的服务器的asmx的url,指定这个地址就可以了
[解决办法]
如果你还没有实际做的话,建议到网上搜索一下相关的实例资料,有很多,基本上大同小异,我就是直接抄过来用的,没什么大问题。当然,我指的是 pb11 以上的资料。
通常并没有必要在 CreateInstance() 中指定服务器地址,因为通过 wsdl 生成的代理对象中已经描述了这些信息;但如果应用服务器的地址改变,而你又不想重新产生 wsdl 来更新代理对象的话,则需要在 CreateInstance() 中指定地址。
如果 ws 不可以匿名访问的话,通过代理访问应用服务器则会产生 401 权限不足的问题,因为 pb 必须通过生成代理对象来调用 ws,所以只好通过 SetProxyServer() 再指定一次应用服务器的地址。
超时的体现就是:如果 ws 的服务器是关着的,而你设置了 timeout=1,你的程序就不会因为等待服务器的响应而“假死”。
[解决办法]
不好意思,我的说法有误!超时设置只有在服务器能够 ping 通的情况下才有效,比如说服务没有启动。对于你的问题,我想有两个解决方案:
一是不使用 ip 地址,改用 ws 主机的域名,这样的话即使 ws 服务器不存在,DNS 的响应时间通常也不会超过 3 秒(当然前提是域名服务器能够正常工作)。
二是在执行 ws 函数前先 ping 一下服务器,在 pb 中调用 api 来模拟 ping 命令比较麻烦,你可以参考一下国外高手 Roland Smith 的代码(适合 pb unicode):
结构体定义:
type icmp_echo_reply from structure
unsignedlongaddress
unsignedlongstatus
unsignedlongroundtriptime
unsignedlongdatasize
unsignedlongreserved[3]
characterdata[]
end type
API 声明:
Function ulong FormatMessage( &
ulong dwFlags, &
ulong lpSource, &
ulong dwMessageId, &
ulong dwLanguageId, &
Ref string lpBuffer, &
ulong nSize, &
ulong Arguments &
) Library "kernel32.dll" Alias For "FormatMessageW"
Function ulong GetLastError() Library "kernel32.dll"
Function ulong inet_addr(string cp) Library "ws2_32.dll" Alias for "inet_addr;Ansi"
Function ulong IcmpCreateFile() Library "icmp.dll"
Function long IcmpSendEcho ( &
ulong IcmpHandle, &
ulong DestinationAddress, &
string RequestData, &
long RequestSize, &
long RequestOptions, &
Ref icmp_echo_reply ReplyBuffer, &
long ReplySize, &
long Timeout &
) Library "icmp.dll" Alias for "IcmpSendEcho"
Function long IcmpCloseHandle(ulong IcmpHandle) Library "icmp.dll"
// -----------------------------------------
// FUNCTION:n_ping.of_FormatMessage
//
// PURPOSE:This function returns the message text for
//the given system error code.
//
// ARGUMENTS:aul_error- Error code
//
// RETURN:Message text
//
// DATEPROG/IDDESCRIPTION OF CHANGE / REASON
// -----------------------------------------------------------------------
// 03/23/2004RolandSInitial coding
// -----------------------------------------
Constant ULong FORMAT_MESSAGE_FROM_SYSTEM = 4096
Constant ULong LANG_NEUTRAL = 0
String ls_buffer, ls_errmsg
ls_buffer = Space(200)
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, &
aul_error, LANG_NEUTRAL, ls_buffer, 200, 0)
ls_errmsg = "Error# " + String(aul_error) + "~r~n~r~n" + ls_buffer
Return ls_errmsg
// -----------------------------------------
// FUNCTION:n_ping.of_WSAGetLastError
//
// PURPOSE:This function returns the message text for
//the most recent Winsock error.
//
// RETURN:Counter value
//
// DATEPROG/IDDESCRIPTION OF CHANGE / REASON
// -----------------------------------------------------------------------
// 03/23/2004RolandSInitial coding
// -----------------------------------------
ULong lul_error
String ls_errmsg
lul_error = WSAGetLastError()
If lul_error = 0 Then
ls_errmsg = "An unknown error has occurred!"
Else
ls_errmsg = of_FormatMessage(lul_error)
End If
Return ls_errmsg
// -----------------------------------------
// FUNCTION:n_ping.of_Ping
//
// PURPOSE:This function performs a 'ping' against the
//server at the specified IP address.
//
// ARGUMENTS:as_ipaddress- IP address of the server
//as_echomsg- The text to send to server
//
// RETURN:True = Success, False = Failed
//
// DATEPROG/IDDESCRIPTION OF CHANGE / REASON
// -----------------------------------------------------------------------
// 03/23/2004RolandSInitial coding
// -----------------------------------------
ULong lul_address, lul_handle
Long ll_rc, ll_size
String ls_errmsg, ls_reply
icmp_echo_reply lstr_reply
lul_address = inet_addr(as_ipaddress)
If lul_address > 0 Then
lstr_reply.Data[Len(as_echomsg)] = ""
lul_handle = IcmpCreateFile()
ll_size = Len(as_echomsg) * 2
ll_rc = IcmpSendEcho(lul_handle, lul_address, &
as_echomsg, ll_size, 0, &
lstr_reply, 28 + ll_size, il_timeout)
IcmpCloseHandle(lul_handle)
If ll_rc = 0 Then
ls_errmsg = of_WSAGetLastError()
MessageBox("Send Echo Error in of_Ping", &
ls_errmsg, StopSign!)
Else
If lstr_reply.Status = 0 Then
ls_reply = String(lstr_reply.Data)
If ls_reply = as_echomsg Then
Return True
Else
ls_errmsg = "The returned string is different:~r~n~r~n"
ls_errmsg += "Sent: " + as_echomsg + "~r~n"
ls_errmsg += "Recv: " + ls_reply
MessageBox("Echo Error in of_Ping", &
ls_errmsg, StopSign!)
End If
Else
ls_errmsg = of_FormatMessage(lstr_reply.Status)
MessageBox("Echo Status Error in of_Ping", &
ls_errmsg, StopSign!)
End If
End If
Else
ls_errmsg = "The given IP Address is invalid!"
MessageBox("Winsock Error in of_Ping", &
ls_errmsg, StopSign!)
End If
Return False
// -----------------------------------------
// FUNCTION:n_ping.of_Ping
//
// PURPOSE:This function provides a default echo string
//to the main of_Ping function.
//
// ARGUMENTS:as_ipaddress- IP address of the server
//
// RETURN:True = Success, False = Failed
//
// DATEPROG/IDDESCRIPTION OF CHANGE / REASON
// -----------------------------------------------------------------------
// 03/23/2004RolandSInitial coding
// -----------------------------------------
String ls_echomsg
ls_echomsg = "abcdefghijklmnopqrstuvwxyz"
Return of_Ping(as_ipaddress, ls_echomsg)