TCP to HTTP Binding?

1231231232121 1 Reputation point
2021-11-26T18:47:52.76+00:00

Hello,

I am trying to figure out WCF API as we help the world, it is good to share info, this is not school anymore. You answer this, and it will be directly applicable to easing the traffic at the ports.

I have a client and a server. The server accepts HTTPS and they don't want that changed. This client sends out data out TCP, aka NetTcpBinding. How do I take the following code and make it outbound as HTTP? Thanks, you'll help the supply chain if you can answer this:

            endPointAddr = "net.tcp://" + textBox2.Text + ":1111/TempusWCF";
            NetTcpBinding tcpBinding = new NetTcpBinding();
            tcpBinding.TransactionFlow = false;
            tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
            tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            tcpBinding.Security.Mode = SecurityMode.None;

            EndpointAddress endpointAddress = new EndpointAddress(endPointAddr);

            Append("Attempt to connect to: " + endPointAddr);

            IService1 proxy = ChannelFactory<IService1>.CreateChannel(tcpBinding, endpointAddress);

            using (proxy as IDisposable)
            {
                Append("Message from server: " + (proxy.HelloWorld(textBox1.Text) + " back to you :)"));
            }
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,771 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,398 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,716 Reputation points Microsoft Vendor
    2021-11-29T08:33:10.767+00:00

    Hi @1231231232121 ,
    Replace NetTcpBinding on the client side with WSHttpBinding to interact with SOAP servers that comply with WS-* protocols.

    EndpointAddress address = new EndpointAddress("https://uri/to/service.svc");  
    WSHttpBinding binding = new WSHttpBinding();  
    IService1 proxy = ChannelFactory<IService1>.CreateChannel(binding, address);  
    

    Here are the docs for details:
    WSHttpBinding: https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.wshttpbinding?view=dotnet-plat-ext-6.0
    Configuring transport security (SSL) for WSHttpBinding: https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-basic-authentication
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments