调用使用WCF通过HTTP和HTTPS Web服务 [英] calling a web service using WCF over Http and Https

查看:425
本文介绍了调用使用WCF通过HTTP和HTTPS Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们有一个运行在HTTP和HTTPS Java Web服务。
我们要在内部和https使用http为我们的web应用程序的外部版本。

In our project we have a java web service that runs over http and https. We want to use http internally and https for the external version of our web app.

所以,我们创建的代理类在我们的应用程序,我们必须安装在web / app.config中的HTTP绑定和一切工作正常。

So we've created the proxy class in our application and we have setup the binding for http in the web/app.config and all works fine.

我们需要什么样的变化作出了code和支持HTTPS在我们的外部应用程序相同的服务的配置?如果可能的话请提供code段解释!

What changes would we need to make to the code and the configuration to support https for the same service in our external application? If possible please supply code snippets to explain!

推荐答案

我找到了答案周围挖MSDN

I found an answer digging around MSDN.

在我的情况下,我使用的是自定义绑定:

In my case, I was using a custom binding:

<customBinding>
    <binding name="jsonpBinding">
        <jsonpMessageEncoding/>
        <httpTransport manualAddressing="true"/>
    </binding>
</customBinding>

这是在服务中引用

<services>
    <service name="{YourInfoHere}">
        <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/>
    </service>
</services>

添加了用于httpsTransport第二个结合,然后是使用的绑定奏效了第二个服务。最终输出:

Adding a second binding that used httpsTransport and then a second service that used that binding did the trick. Final output:

    <services>
        <service name="{YourInfoHere}">
            <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/>
            <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBindingHttps" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/>
        </service>
    </services>
    <bindings>
        <customBinding>
            <binding name="jsonpBinding">
                <jsonpMessageEncoding/>
                <httpTransport manualAddressing="true"/>
            </binding>
            <binding name="jsonpBindingHttps">
                <jsonpMessageEncoding/>
                <httpsTransport manualAddressing="true" />
            </binding>
        </customBinding>
    </bindings>

可能不是很理想,但它的作品。这些只是我取得了令SSL工作的变化。因为它是所有在绑定和放大器;交通方面,code保持不变。

May not be ideal, but it works. These were the only changes I made to make SSL work. Since it is all in the binding & transport, the code remains the same.

相关链接MSDN:


  1. 自定义绑定:<一href=\"http://msdn.microsoft.com/en-us/library/ms731377.aspx\">http://msdn.microsoft.com/en-us/library/ms731377.aspx

  2. HttpTransport:<一href=\"http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.aspx\">http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.aspx

  3. HttpsTransport:<一href=\"http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpstransportbindingelement.aspx\">http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpstransportbindingelement.aspx

这篇关于调用使用WCF通过HTTP和HTTPS Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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