doushu9253 2012-10-19 17:54
浏览 71
已采纳

在VB.Net中使用PHP Web服务

Here is the code I received from a customer on how they access their web service from PHP. I will need to do the same but from VB.Net. There is no WSDL available and this is all the code I have from them. Is this even possible?

$Client = new SoapClient(NULL, array('location' => 'http://ipaddress/onyx/api/soap_api.php', 'uri' => 'not-used'));

print_r($Client->qty_available('124044'));

/* Output: Array ( [01] => Array ( [available] => 333 [name] => Alliance )

  • 写回答

2条回答 默认 最新

  • douyu0845 2012-10-19 18:20
    关注

    If the data being returned is in a custom format (I'm guessing this from the question) then the default web service stuff might not work in .Net, you'll have to manually get the data from the request and parse it based on what the service returns. If it is in a standard XML, you may have to get the raw data once just to create the WSDL yourself.

    Here is some code from a console app we used to test one of our .Net web services. Basically its making the request and returning the raw data. You could run this once to get the data that is returned, and then write the code to parse the data. I replaced our values with the ones from your question.

    Module Module1
    
    Sub Main()
    
    
        Dim x = System.Net.HttpWebRequest.Create("http://ipaddress/onyx/api/soap_api.php")
    
        x.Method = "POST"
    
        Dim MemStream As New System.IO.MemoryStream
    
        Dim ReqData As New IO.StreamWriter(MemStream, System.Text.Encoding.UTF8)
        ReqData.Write(My.Resources.Test2)
        ReqData.Flush()
    
        x.ContentLength = MemStream.Length
        x.ContentType = "text/xml; charset=utf-8"
        x.Headers.Add("SOAPAction", "not-used")
    
        Dim WebReq = x.GetRequestStream
        WebReq.Write(MemStream.GetBuffer, 0, MemStream.Length)
        WebReq.Flush()
        WebReq.Close()
    
        Dim Res As System.Net.HttpWebResponse = x.GetResponse
    
        If Res.StatusCode = Net.HttpStatusCode.OK Then
            Dim SR = New IO.StreamReader(Res.GetResponseStream)
            Console.WriteLine(SR.ReadToEnd)
        Else
            Console.WriteLine(Res.StatusCode & ", " & Res.StatusDescription)
        End If
    
        Console.ReadLine()
    
    End Sub
    
    End Module
    

    The `My.Resources.Test2' is the pre-formatted request data we were using. Here is a possible example for your situation, it may not be correct.

    <?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>
        <qty_available>
             124044
        </qty_available>
    </soap:Body>
    </soap:Envelope>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?