C# WCF服务未在浏览器中打开?
我正在学习WCF,我开始创建一个非常基本的主机应用程序,它用一个方法定义一个类,如下所示:C# WCF服务未在浏览器中打开?,c#,wcf,C#,Wcf,我正在学习WCF,我开始创建一个非常基本的主机应用程序,它用一个方法定义一个类,如下所示: [ServiceContract()] public interface IMath { [OperationContract] int Add(int a, int b); } public class MathCalcs : IMath { public MathCalcs() {
[ServiceContract()]
public interface IMath
{
[OperationContract]
int Add(int a, int b);
}
public class MathCalcs : IMath
{
public MathCalcs()
{
Console.WriteLine("Service await two numbers...");
}
public int Add(int a, int b)
{
return a + b;
}
}
这就是我配置App.config文件的方式:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="ConsoleHost.MathCalcs" behaviorConfiguration="MathServiceMEXBehavior">
<endpoint address="http://localhost:8080/MathCalcs"
binding="basicHttpBinding"
contract="ConsoleHost.IMath"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MathCalcs"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MathServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
但是它无法通过URI查看服务的元数据,我确信我在阅读这本书时正确地遵循了这些步骤,并且前面的示例运行良好,唯一的区别是我没有在独立类库中分离服务逻辑(接口和类)。
我遗漏了什么?这里有一个相关的帖子,我认为它可能会引导你走向正确的方向
我认为这是一篇相关的文章,它可能会引导你朝着正确的方向前进
下面的代码行
Console.ReadLine();
必须位于using子句的大括号内!
完成后,请重试查找WSDL元数据。以下代码行
Console.ReadLine();
必须位于using子句的大括号内!
完成后,请重试查找WSDL元数据