连接 Visual Basic 到 C# WCF

huangapple go评论67阅读模式
英文:

Connecting Visual Basic to C# WCF

问题

这是我已经完成的部分:

  • 右键单击以添加服务引用。
  • Visual Basic 创建了一个名为 App_WebReferences 的文件夹,其中包含 ServiceReference1 文件夹。在 ServiceReference1 文件夹内,它包含了 Reference.svcmap 文件。
  • Reference.svcmap 文件内,包含了更多带有扩展名 .svcinfo.disco.wsdl.xsd 的文件。

我该如何从我的 Visual Basic .aspx.vb 网页表单中调用 WCF 操作契约?

英文:

I have some services built with C# WCF and this service is self-hosted. My main application is built with visual basic and with the .NET Framework. I have a webform in .aspx.vb and I want to connect to the services in C# WCF.

This is what I have done:

  • Right-click to add service reference.
  • Visual Basic created a App_WebReferences folder with ServiceReference1 folder. Inside the ServiceReference1 folder, it contains the Reference.svcmap.
  • Inside the Reference.svcmap, there are more files with the extensions .svcinfo, .disco, .wsdl, .xsd.

How do I call the WCF operation contracts from my Visual Basic .aspx.vb web form?

答案1

得分: 1

以下是翻译好的部分:

服务器和客户端的语言差异通常不会产生很大影响。因为您发送带有参数的请求给服务进行处理,它只会返回给您一个结果。

例如:

我有一个用C#编写的WCF服务:

public class Service1 : IService1
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
        if (composite == null)
        {
            throw new ArgumentNullException("composite");
        }
        if (composite.BoolValue)
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }
}

客户端代码:

Module Module1
    
    Sub Main()
        Dim client As Service1Client = New Service1Client()
        Dim result As String = client.GetData(1)
        Console.WriteLine(result)
        Console.ReadLine()
    End Sub

End Module

输出:
连接 Visual Basic 到 C# WCF

英文:

The difference in the language of the server and client generally does not have a big impact. Because you send a request with parameters to the service to process, it will only return you a result.

For example:

I have a WCF service in C#:

public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }

Client code:

  Module Module1
    
        Sub Main()
            Dim client As Service1Client = New Service1Client()
            Dim result As String = client.GetData(1)
            Console.WriteLine(result)
            Console.ReadLine()
        End Sub

End Module

Output:
连接 Visual Basic 到 C# WCF

huangapple
  • 本文由 发表于 2023年7月10日 17:40:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652515.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定