pb9生成webservice对象如何改服务地址

Powertion 2011-01-28 03:25:23
开发时webservice对象建立后deploy后调用
但开发时的webservice服务地址与实际应用地址并不一致,移植也同样存在上述问题

有没有办法直接修改web服务地址,或者把服务地址做成参数调用

现在用的是pb9,据说pb11的createinstance函数具有地址参数
...全文
594 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sfgxtd 2011-11-02
  • 打赏
  • 举报
回复
我的代理服务器也生成不了,忘高手指点一二。。
做梦的猫 2011-02-13
  • 打赏
  • 举报
回复
不好意思,我的说法有误!超时设置只有在服务器能够 ping 通的情况下才有效,比如说服务没有启动。对于你的问题,我想有两个解决方案:
一是不使用 ip 地址,改用 ws 主机的域名,这样的话即使 ws 服务器不存在,DNS 的响应时间通常也不会超过 3 秒(当然前提是域名服务器能够正常工作)。

二是在执行 ws 函数前先 ping 一下服务器,在 pb 中调用 api 来模拟 ping 命令比较麻烦,你可以参考一下国外高手 Roland Smith 的代码(适合 pb unicode):


结构体定义:
type icmp_echo_reply from structure
unsignedlong address
unsignedlong status
unsignedlong roundtriptime
unsignedlong datasize
unsignedlong reserved[3]
character data[]
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
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial 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
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial 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
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial 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
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial coding
// -----------------------------------------------------------------------------

String ls_echomsg

ls_echomsg = "abcdefghijklmnopqrstuvwxyz"

Return of_Ping(as_ipaddress, ls_echomsg)
Powertion 2011-02-10
  • 打赏
  • 举报
回复
pb8的回答:
1。在pb9中CreateInstance()无第3个参数portname哦
2。你所说的"使用设置代理服务器的访问参数的",不会是指IE代理服务器吧,WS好像都会调用IE代理呢




msgtogcr的回答:
我设置了 timeout=3,指定一个错误的IP,实际上3秒并不退出,而是漫长的等待后蹦出系统错误

l1=conn.setoptions( 'Timeout=2')
l2=conn.setproxyserveroptions("address='http://192.168.22.61/x.asmx'")
rc = conn.createinstance(obj,"x1Soap")

try
//如何超时退出?如何捕获错误?
id=obj.getGuestInfo( '2010-12-16', 'CZ378', '109')
catch ( exception e )
messagebox("error",e.text )
finally

destroy conn
end try
做梦的猫 2011-01-30
  • 打赏
  • 举报
回复
如果你还没有实际做的话,建议到网上搜索一下相关的实例资料,有很多,基本上大同小异,我就是直接抄过来用的,没什么大问题。当然,我指的是 pb11 以上的资料。

通常并没有必要在 CreateInstance() 中指定服务器地址,因为通过 wsdl 生成的代理对象中已经描述了这些信息;但如果应用服务器的地址改变,而你又不想重新产生 wsdl 来更新代理对象的话,则需要在 CreateInstance() 中指定地址。

如果 ws 不可以匿名访问的话,通过代理访问应用服务器则会产生 401 权限不足的问题,因为 pb 必须通过生成代理对象来调用 ws,所以只好通过 SetProxyServer() 再指定一次应用服务器的地址。

超时的体现就是:如果 ws 的服务器是关着的,而你设置了 timeout=1,你的程序就不会因为等待服务器的响应而“假死”。
pb8 2011-01-30
  • 打赏
  • 举报
回复
你在#3楼使用的函数是使用设置代理服务器的访问参数的~~
pb8 2011-01-30
  • 打赏
  • 举报
回复
conn.CreateInstance (ref powerobject proxy_obj, string proxy_name, {string portname}) throws SoapException

Argument Description
conn The name of the SoapConnection object that establishes the connection
proxy_obj The referenced name of your proxy object
proxy_name The 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,指定这个地址就可以了
Powertion 2011-01-30
  • 打赏
  • 举报
回复
大致知道pb9用
setProxyServerOptions()
setOptions()

setOptions('timeout=3')设置成功,不知道怎么体现这个超时
try..catch也捕获不到错误,求完整实例
做梦的猫 2011-01-28
  • 打赏
  • 举报
回复
pb12 里面可以通过 SetProxyServer() 指定服务器地址和端口;通过 SetOption() 指定超时等待时间。
Powertion 2011-01-28
  • 打赏
  • 举报
回复
还有疑问,pb客户端调用webservice如何设置超时?有没有好的解决方案?

662

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder Web 应用
社区管理员
  • Web 应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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