我已經創建了wcf
服務,但是當我運行時,它顯示這樣的錯誤。無法運行我的wcf服務
我已經使用重命名工具更改名稱類和接口名稱。 下面是service.cs類代碼
public class MyTest : MyServices
{
public string MyTask1(string a)
{
return "Hello " + a;
}
public string MyTask2(DataContract1 dc)
{
return "Hello " + dc.fname;
}
}
這裏是我的界面代碼:
[ServiceContract]
public interface MyServices
{
[OperationContract]
string MyTask1(string myValue);
[OperationContract]
string MyTask2(DataContract1 dcValue);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class DataContract1
{
string firstName;
string lastName;
[DataMember]
public string fname
{
get { return firstName; }
set { firstName = value; }
}
public string lname
{
get { return lastName; }
set { lastName = value; }
}
}
我已經編輯我的web.config文件,並添加這些行(我在黑閱讀書)
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
</service>
這裏是我的system.servicemodel代碼
<system.serviceModel>
<services>
<!-- My Custimization -->
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
我不明白這一行,它是爲什麼寫的 –
這是獲取元數據或服務描述的綁定。如果禁用,則無法獲取wsdl。 –
你可以顯示你的'ServiceBehavior'配置嗎?或者最好是整個''部分? –
Szymon