Deploying WCF Tutorial App on IIS7: “The type could not be found”

后端 未结 4 1403
北荒
北荒 2020-12-31 09:37

I\'ve been trying to follow this tutorial for deploying a WCF sample to IIS . I can\'t get it to work. This is a hosted site, but I do have IIS Manager access to the server.

相关标签:
4条回答
  • 2020-12-31 09:55

    In order to create a new application, right-click on the Default Web Site node. From the context menu select Add Application.

    0 讨论(0)
  • 2020-12-31 10:03

    I had this issue.

    1. I kept published files under wwwroot
    2. Click Browse on .svc file
    3. This throwing same exception

    Resolution

    1. I created a virtual directory for the same
    2. Tries Browse on .svc file.

    Working...

    0 讨论(0)
  • 2020-12-31 10:07

    Well, it seems I got this to work. I still can't find the "Create Application" item in IIS Manager. That part is kind of frustrating, but I'm glad it appears to be working anyway.

    I had create the physical directory IISHostedCalcService under wwwroot. That was creating some confusion; it meant that http://test.com.cws1.my-hosting-panel.com/IISHostedCalcService/Service.svc was almost working, but it shouldn't. I moved IISHostedCalcService outside wwwroot and now the only place to access the service is http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc .

    Then, accessing http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc was throwing that "This collection already contains an address with scheme http.
    There can be at most one address per scheme in this collection." error. It turns out the solution to that is to add the following to the web.config file, right under system.serviceModel:

    <serviceHostingEnvironment>
      <baseAddressPrefixFilters>
        <add prefix="http://test.com.cws1.my-hosting-panel.com"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    

    After that I got a new error when ccessing http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/Service.svc : "The contract name IMetadataExchange could not be found in the list of contracts implemented by the service CalculatorService". It turns out the solution to that is to modify the web.config file as follows (i.e., add the behaviors section, and behaviorConfiguration="SimpleServiceBehavior" in the service element):

    <configuration>
      <system.serviceModel>
        <serviceHostingEnvironment>
          <baseAddressPrefixFilters>
            <add prefix="http://test.com.cws1.my-hosting-panel.com"/>
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        <services>
          <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="SimpleServiceBehavior">
          ...
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SimpleServiceBehavior">
              <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <system.web>
        <customErrors mode="Off"/>
      </system.web>
    </configuration>
    

    Finally, I was able to create client proxies by pointing svcutil at http://test.com.cws1.my-hosting-panel.com/IISHostedCalc/service.svc?wsdl in step 5c of the tutorial at http://msdn.microsoft.com/en-us/library/ms733133.aspx . However, when I ran the client, I got a "The caller was not authenticated by the service" error. The solution to this was the simplest: just change binding="wsHttpBinding" to binding="basicHttpBinding" in the service's web.config and the client's web.config (or re-run svcutil after changing the service's web.config).

    The web.config ended up looking like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <serviceHostingEnvironment>
          <baseAddressPrefixFilters>
            <add prefix="http://test.com.cws1.my-hosting-panel.com"/>
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        <services>
          <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="SimpleServiceBehavior">
    
            <!-- This endpoint is exposed at the base address provided by host:                                        http://localhost/servicemodelsamples/service.svc  -->
            <endpoint address=""
                      binding="basicHttpBinding"
                      contract="Microsoft.ServiceModel.Samples.ICalculator" />
    
            <!-- The mex endpoint is explosed at http://localhost/servicemodelsamples/service.svc/mex -->            
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" />
    
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SimpleServiceBehavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
              <!-- 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="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
      <system.web>
        <customErrors mode="Off"/>
      </system.web>
    </configuration>
    
    0 讨论(0)
  • 2020-12-31 10:08

    I had the same error and for me the problem was just that I was missing assemblies on the server that were needed by the service to compile.

    All that is described here was not necessary to me.

    To find out what your error is, you can try to move your service.svc and service.svc.cs files to the App_Code directory. That way you will get an error message better related to the real error you have.

    In my case, the namespace that was missing because I forgot to deploy some assemblies. I uploaded the missing assemblies, run the service correctly then moved back the services files were they belonged.

    0 讨论(0)
提交回复
热议问题