任何帮助都是适当的 我有一个Sample服务和一个Test console应用程序 我通过将同一个soln的引用添加到控制台appln来访问示例服务元数据,并且我正在获取绑定信息。 我也在IIS中托管(发布)相同的服务,并通过Test Console appln中的服务URL添加引用,我正在获得结果。
现在问题是我正在运行IIS中托管(发布)的数据服务我正在添加引用并尝试从服务URL读取元数据它给我错误。 元数据包含无法解析的引用:'http:// localhost:9092 / TransactionDataService.svc / mex' 。
我在两个(样本+我正在运行的数据服务)案例中使用mexhttpbinding和multiplebingind = true
samp-le serviec的web配置
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ServiceApp.Service1">
<endpoint address="" binding="wsHttpBinding" name="Service1Endpoint" contract="ServiceApp.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
访问元数据的代码
EndpointAddress serviceEndpointAddress = new EndpointAddress("http://localhost:30617/Service1.svc/mex");
var endpointCollection = MetadataResolver.Resolve(typeof(IService1), serviceEndpointAddress);
foreach (var endpoint in endpointCollection)
{
Type bindingType = endpoint.Binding.GetType();
if (bindingType.Equals(typeof(WSHttpBinding)))
{
Console.WriteLine("Eureka!!!");
}
}
数据服务的网络配置
<bindings>
<wsHttpBinding>
<binding name="WSHttp" openTimeout="01:00:00" closeTimeout="01:00:00" sendTimeout="01:00:00" receiveTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="0" maxReceivedMessageSize="2147483647">
<reliableSession enabled="true" />
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<!--Service Behaviors-->
<behaviors>
<serviceBehaviors>
<behavior name="DataAccessBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<!--Service Configuration-->
<services>
<service name="TransactionDataAccess" behaviorConfiguration="DataAccessBehavior">
<endpoint name="DataAccessServiceEndpoint" address="" binding="wsHttpBinding" bindingConfiguration="WSHttp" contract="TransactionDataServices.ITransactionDataService"/>
<endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
访问数据服务元数据的代码与serviec url
相同答案 0 :(得分:2)
查看您是否忘记使用[DataContract]
属性装饰已运输的课程(不要忘记[DataMember]
)。