需要帮助消耗第三方Web服务 [英] Need Help Consuming 3rd Party Web Service

查看:62
本文介绍了需要帮助消耗第三方Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对VS非常陌生,并使用此Lightswitch项目让自己了解Visual Basic,我认为RESTful请求将是一个不错的开始.

I am very new to VS and using this Lightswitch project to expose myself to understanding Visual Basic, and I thought RESTful requests would be a good start.

我正在尝试访问GPS服务,并已获得VS2013来创建服务参考,并收到了自动生成的"reference.vb",我认为它是代理类?它似乎包含从服务调用的函数.

I'm trying to access a GPS service, and have gotten VS2013 to create the Service Reference, and received an auto generated 'reference.vb' which I believe to be the proxy class? It seems to contains functions to call from the service.

<System.Runtime.Serialization.DataMemberAttribute()>  _
        Public Property LastUpdate() As Date
            Get
                Return Me.LastUpdateField
            End Get
            Set
                If (Me.LastUpdateField.Equals(value) <> true) Then
                    Me.LastUpdateField = value
                    Me.RaisePropertyChanged("LastUpdate")
                End If
            End Set
        End Property
        
        <System.Runtime.Serialization.DataMemberAttribute()>  _
        Public Property MotionState() As String
            Get
                Return Me.MotionStateField
            End Get
            Set
                If (Object.ReferenceEquals(Me.MotionStateField, value) <> true) Then
                    Me.MotionStateField = value
                    Me.RaisePropertyChanged("MotionState")
                End If
            End Set
        End Property

不幸的是,供应商仅提供了C#请求的示例,而我实际上仅在使用VB.我了解我有很多要学习的代码,我只是想看整个图片.
这是他们给出的C#REST请求示例.

Unfortunately the vendor only provides examples of C# requests, and I'm really only using VB. I understand I have a lot to learn regarding the code, I'm just trying to see the whole picture.
Here is a sample C# REST request they have given.

我不确定代码转换器是否真的是我注意到的方法.但是我阅读的每个教程在request和VS的不同版本中似乎都有不同之处,所以我感到困惑.鉴于我已将其正确转换为VB,在哪里 实际返回结果信息的表元素是什么? (对不起,很愚蠢的问题)

I'm not sure code converters are really the way to go for this I have noticed. But every tutorial I read seems to do something different in the request , and in different versions of VS so I get confused. Given that I properly convert this to VB, where is the table element this actually returning the result information to? (Sorry very stupid questions)

// Create HTTP GET request using driver web service
string uri = @"https://ws.examplegps.com/DriverWebService.svc/drivers/?limit=2&offset=1";
var request = System.Net.HttpWebRequest.Create(uri);
request.Method = "GET";

// Create authorization header (replace these values with actual credentials)
string companyLoginId = "{LogonID}";
string userName = "{UserName}";
string password = "{Password}";
string auth = companyLoginId + "|" + userName + ":" + password;
string authHeader = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(auth));
request.Headers["Authorization"] = authHeader;

// Request response from web service
try
{
    var httpWebResponse = (System.Net.HttpWebResponse)request.GetResponse();

    // Get response as string
    string strResponse;
    var responseEncoding = System.Text.Encoding.GetEncoding(httpWebResponse.CharacterSet);
    using (System.IO.StreamReader reader = new System.IO.StreamReader(httpWebResponse.GetResponseStream(),responseEncoding))
    {
        strResponse = reader.ReadToEnd();
    }
    Console.WriteLine(strResponse);
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}

(我已将自定义绑定添加到web.config中)

(I have added the custom binding to web.config)

我引用了这些链接,这些链接看起来真的很不一样

I have referenced these links which all seem really different

这最有意义,但这是SOAP吗?

This makes the most sense but it's SOAP?

Lightswitch-消耗Web服务

非常感谢耐心的对话.


推荐答案

你好

我有点困惑.您要达到什么目标?从外部服务获取数据并将此数据输入到lightswitch实体中,还是要共享lightsitzchch数据库,以便任何人都可以从LS获取数据?

I am a litle bit confused. What do you want to achive? Getting Data from an external Service and enter this data into a lightswitch entity or do you want to share the lightswitzch database so anyone can get data from LS?

亲切的问候

托马斯


这篇关于需要帮助消耗第三方Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆