如何使用托管在IIS上的wsHttpBinding和Web上的消耗品来配置WCF服务?

时间:2015-05-11 07:33:12

标签: web-services wcf iis web-config wshttpbinding

我对WCF服务一般没有经验(这是我创建,配置和使用WCF服务的第一次尝试)。

  1. 我已经创建了我的WCF服务,通过WCF测试客户端(在“Visual Studio”中的“开发PC”上)进行了测试,一切正常。
  2. 我在我们的服务器(不是开发PC)上的IIS中托管它,将其添加到ASP.Net v4.0应用程序池,使用Windows Forms Application(来自开发PC)对其进行了测试,其中我添加了服务参考托管的WCF服务,一切正常。
  3. 我在家用电脑上尝试过相同的应用程序(和application.config),我收到此错误:“调用者未通过服务验证”。
  4. 我曾试图“谷歌它”,大多数人说错误是由不同域上的计算机引起的(这是因为我的家用电脑和工作中的服务器甚至不在同一个网络上),但我认为WCF可以通过Web使用,还是我认为是错误的?

    On Development PC, WCF Service address is redirected to Local IP of Server PC. I've also added REST/Web Service because I need to POST some data and it's consumable without any problems.

    我有什么遗失的吗?

    的Web.config:

    <?xml version="1.0"?>
    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
    
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5"/>
      </system.web>
    
      <system.serviceModel>
    
        <services>
            <service name="TestWCF.TestServis">
                <endpoint address="TestWCF" binding="wsHttpBinding" contract="TestWCF.ITestServis" />
            </service>
    
            <service name="TestWCF.TestPushingServis">
                <endpoint address="" binding="webHttpBinding" contract="TestWCF.ITestPushingServis" behaviorConfiguration="web" />
            </service>
        </services>
    
        <behaviors>
    
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>     
          </serviceBehaviors>
    
          <endpointBehaviors>
            <behavior name="web">
                <webHttp />
            </behavior>
          </endpointBehaviors>
    
        </behaviors>
    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. -->
        <directoryBrowse enabled="true"/>
      </system.webServer>
    
    </configuration>
    

    Application.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
        </configSections>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
        <system.serviceModel>
            <bindings>
                <wsHttpBinding>
                    <binding name="WSHttpBinding_ITestServis"
                             maxReceivedMessageSize="2147483647" />
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://testdomain.com:12345/TestServis.svc/TestWCF"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITestServis"
                    contract="TestServisReference.ITestServis"
                    name="WSHttpBinding_ITestServis">
                    <identity>
                        <servicePrincipalName value="host/ServerName" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>
    </configuration>
    

1 个答案:

答案 0 :(得分:1)

对于wsHttpBinding,您可能需要使用ClientCredentials属性设置Windows凭据(用户名,密码和Windows域)。

from PyQt4 import QtGui

class Calculus:
    def __init__(self):
        print "object created"

    @staticmethod
    def update_progress(self,value,ui_object): 
        ui_object.setText(QtGui.QApplication.translate("Dialog", "Progress: %s %%" % value, None))

        #MEMORY LEAK WHEN UPDATING TOO MUCH (H=0.0001 AND B=1000)
        QtGui.QApplication.processEvents() #update gui for pyqt



    @staticmethod
    def euler(b,h,progress):
        #progress is an UI object, a label for example.
        actions_done = 0
        actions_number = b * (1./h) #t = t+h. When h = 0.01 we need to perform t=t+h 100(1/h) times to get 1. 
                                    #when t varies from 0 to b, then we need to multiply this 1 * b(end time)
                                    #so we get b * (1/h) as a number of actions to perform

        scale = actions_number * 0.01

        while t <= b:
            actions_done+=1
            progress_value = (actions_done/actions_number)*100

            if (actions_done % scale == 0):
                Calculus.update_progress(None,progress_value, progress)         

            t += h

另外 - 您可以尝试在绑定中将安全模式设置为none:

yourClient.ClientCredentials.Windows.ClientCredential.UserName = "name"
yourClient.ClientCredentials.Windows.ClientCredential.Password = "password"
yourClient.ClientCredentials.Windows.ClientCredential.Domain = "domain"

希望它有所帮助,

的Pawel