我是WCF的新手,正在开展一个项目 我正在构建一个被调用的WCF库 通过Web项目(ASP.NET 2.03.5 / C#)。
我在这里发生了一些事情。
1)我为我提供了一份恭维合同(IJSON) 我的JSON Web方法的SOAP契约(ISOAP)。 2)我有一个处理的合同IFileTransferService 文件流。
请你看看我的APP.CONFIG和WEB.CONFIG 文件并告诉我他们看起来是否正确或是否正在复制 我的Web.Config中的App.Config中不必要的内容? 如果我使用服务库,我真的需要做 事情两次(声明服务,绑定等)?看起来这样吗 对?
此外,还有任何其他风格/建设性意见 我身边的系统.serviceModel总是受到赞赏。
感谢您的时间。
WEB.CONFIG
<system.serviceModel>
<client>
<endpoint name="MySOAPAuthEP"
address="http://localhost:1241/WebProj/auth.svc/soap"
binding="basicHttpBinding"
bindingConfiguration="soapWeb"
contract="Project.WebAPI.Authentication.ISOAPAuthService" />
<endpoint name="MySOAPTradeEP"
address="http://localhost:1241/WebProj/trade.svc/soap"
binding="basicHttpBinding"
bindingConfiguration="soapWeb"
contract="Project.WebAPI.Trade.ISOAPTradeService" />
<endpoint name="MySOAPFileTransferEP"
address="http://localhost:1241/WebProj/filetransfer.svc/soap"
binding="basicHttpBinding"
bindingConfiguration="httpLargeDataStream"
contract="Project.WebAPI.FileTransfer.ISOAPFileTransferService" />
<endpoint name="MyJSONAuthEP"
binding="webHttpBinding"
bindingConfiguration="jsonWeb"
contract="Project.WebAPI.Authentication.IJSONAuthService" />
<endpoint name="MyJSONTradeEP"
binding="webHttpBinding"
bindingConfiguration="jsonWeb"
contract="Project.WebAPI.Trade.IJSONTradeService" />
<endpoint name="MyJSONFileTransferEP"
binding="webHttpBinding"
bindingConfiguration="jsonWeb"
contract="Project.WebAPI.FileTransfer.IJSONFileTransferService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="soapWeb" />
<binding name="httpLargeDataStream" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferSize="65536"
maxReceivedMessageSize="2147483647" messageEncoding="Mtom" transferMode="Streamed">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="jsonWeb" maxBufferSize="1500000" maxBufferPoolSize="1500000"
maxReceivedMessageSize="1500000">
<readerQuotas maxDepth="32" maxStringContentLength="656000" maxArrayLength="656000"
maxBytesPerRead="656000" maxNameTableCharCount="656000" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebHttpEPBehavior">
<webHttp />
</behavior>
<behavior name="BasicHttpEPBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Default" name="Project.WebAPI.Trade.TradeService">
<endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
binding="webHttpBinding" name="MyJSONTradeEP" contract="Project.WebAPI.Trade.IJSONTradeService" />
<endpoint address="soap" binding="basicHttpBinding" name="MySOAPTradeEP"
contract="Project.WebAPI.Trade.ISOAPTradeService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1243/WebProj/trade.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Default" name="Project.WebAPI.Authentication.AuthService">
<endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
binding="webHttpBinding" name="MyJSONAuthEP" contract="Project.WebAPI.Authentication.IJSONAuthService" />
<endpoint address="soap" binding="basicHttpBinding" name="MySOAPAuthEP"
contract="Project.WebAPI.Authentication.ISOAPAuthService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1242/WebProj/auth.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Default" name="Project.WebAPI.FileTransfer.FileTransferService">
<endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
binding="webHttpBinding" name="MyJSONFileTransferEP" contract="Project.WebAPI.FileTransfer.IJSONFileTransferService" />
<endpoint address="soap"
binding="basicHttpBinding"
name="MySOAPFileTransferEP"
bindingConfiguration="httpLargeDataStream"
contract="Project.WebAPI.FileTransfer.ISOAPFileTransferService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1244/WebProj/filetransfer.svc" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
的app.config
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="soapWeb" />
<binding name="httpLargeDataStream"
maxReceivedMessageSize="2147483647"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transferMode="Streamed"
messageEncoding="Mtom"
maxBufferSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="jsonWeb" maxBufferSize="1500000" maxBufferPoolSize="1500000"
maxReceivedMessageSize="1500000">
<readerQuotas maxDepth="32" maxStringContentLength="656000" maxArrayLength="656000"
maxBytesPerRead="656000" maxNameTableCharCount="656000" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Default" name="Project.WebAPI.Trade.TradeService">
<endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
binding="webHttpBinding" name="MyJSONTradeEP" contract="Project.WebAPI.Trade.IJSONTradeService" />
<endpoint address="soap" binding="basicHttpBinding" name="MySOAPTradeEP"
contract="Project.WebAPI.Trade.ISOAPTradeService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1243/WebProj/trade.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Default" name="Project.WebAPI.Authentication.AuthService">
<endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
binding="webHttpBinding" name="MyJSONAuthEP" contract="Project.WebAPI.Authentication.IJSONAuthService" />
<endpoint address="soap" binding="basicHttpBinding" name="MySOAPAuthEP"
contract="Project.WebAPI.Authentication.ISOAPAuthService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1242/WebProj/auth.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Default" name="Project.WebAPI.FileTransfer.FileTransferService">
<endpoint address="json" behaviorConfiguration="WebHttpEPBehavior"
binding="webHttpBinding" name="MyJSONFileTransferEP" contract="Project.WebAPI.FileTransfer.IJSONFileTransferService" />
<endpoint address="soap" binding="basicHttpBinding" name="MySOAPFileTransferEP"
contract="Project.WebAPI.FileTransfer.ISOAPFileTransferService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1244/WebProj/filetransfer.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebHttpEPBehavior">
<webHttp />
</behavior>
<behavior name="BasicHttpEPBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
答案 0 :(得分:0)
有几条评论可帮助您整理配置文件并使其更具可读性:
<services>
和<client>
部分。为什么?这通常不是必需的 - 服务器端(运行服务器代码的地方)需要<services>
,而调用服务器的客户端只需要<client>
部分<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
设置吗?这基本上“伪造”了WCF服务中的HttpContext,这样它们的外观和行为就像ASMX webservices一样 - 你需要这个吗?<serviceDebug includeExceptionDetailInFaults="true" />
可能在开发/测试环境中很有用,但我绝对建议将其删除以进行生产<baseAddress>
条目;在IIS托管环境中,基地址被忽略,因为* .svc文件(它所在的虚拟目录)的位置是你的基地,你不能覆盖它乍一看是这样: - )
马克