Visual Studio basicHttpBinding和端点问题

[英]Visual Studio basicHttpBinding and endpoint problems


I have a WPF application in VS 2008 with some web service references. For varying reasons (max message size, authentication methods) I need to manually define a number of settings in the WPF client's app.config for the service bindings.

我在VS 2008中有一个带有一些Web服务引用的WPF应用程序。由于各种原因(最大消息大小,身份验证方法),我需要在WPF客户端的app.config中为服务绑定手动定义许多设置。

Unfortunately, this means that when I update the service references in the project we end up with a mess - multiple bindings and endpoints. Visual Studio creates new bindings and endpoints with a numeric suffix (ie "Service1" as a duplicate of "Service"), resulting in an invalid configuration as there may only be a single binding per service reference in a project.

不幸的是,这意味着当我更新项目中的服务引用时,我们最终会陷入混乱 - 多个绑定和端点。 Visual Studio使用数字后缀(即“Service1”作为“Service”的副本)创建新绑定和端点,导致配置无效,因为项目中每个服务引用可能只有一个绑定。

This is easy to duplicate - just create a simple "Hello World" ASP.Net web service and WPF application in a solution, change the maxBufferSize and maxReceivedMessageSize in the app.config binding and then update the service reference.

这很容易复制 - 只需在解决方案中创建一个简单的“Hello World”ASP.Net Web服务和WPF应用程序,在app.config绑定中更改maxBufferSize和maxReceivedMessageSize,然后更新服务引用。

At the moment we are working around this by simply undoing checkout on the app.config after updating the references but I can't help but think there must be a better way!

目前我们正在解决这个问题,只需在更新引用后撤消app.config上的checkout,但我不禁想到必须有更好的方法!

Also, the settings we need to manually change are:

此外,我们需要手动更改的设置是:

<security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" />
</security>

and:

<binding maxBufferSize="655360" maxReceivedMessageSize="655360" />

We use a service factory class so if these settings are somehow able to be set programmatically that would work, although the properties don't seem to be exposed.

我们使用服务工厂类,所以如果这些设置能够以某种方式以编程方式设置,那么虽然这些属性似乎没有公开。

5 个解决方案

#1


2  

Create a .Bat file which uses svcutil, for proxygeneration, that has the settings that is right for your project. It's fairly easy. Clicking on the batfile, to generate new proxyfiles whenever the interface have been changed is easy.

创建一个.bat文件,该文件使用svcutil进行代理生成,该文件具有适合您项目的设置。这很容易。单击bat文件,只要界面被更改就生成新的代理文件很容易。

The batch can then later be used in automated builds. Then you only need to set up the app.config (or web.config) once. We generally separate the different configs for different environments, such as dev, test prod.

然后可以将批处理用于自动构建中。然后你只需要设置一次app.config(或web.config)。我们通常会针对不同的环境分离不同的配置,例如dev,test prod。

Example (watch out for linebreaks):

示例(注意换行):

REM generate meta data
call "SVCUTIL.EXE" /t:metadata "MyProject.dll" /reference:"MyReference.dll"

REM making sure the file is writable
attrib -r "MyServiceProxy.cs"

REM create new proxy file
call "SVCUTIL.EXE" /t:code *.wsdl *.xsd /serializable /serializer:Auto /collectionType:System.Collections.Generic.List`1  /out:"MyServiceProxy.cs" /namespace:*,MY.Name.Space /reference:"MyReference.dll" 

:)

//W

#2


2  

Rather than changing the generated endpoint, uou could add a second endpoint and binding definition with the configuration you need, then in your code just put the name of the new endpoint in your service client constructor.

您可以使用所需的配置添加第二个端点和绑定定义,而不是更改生成的端点,然后在代码中将新端点的名称添加到服务客户端构造函数中。

#3


0  

Somehow I prefer using svcutil.exe directly than to use the "Add Service Reference" feature of Visual Studio :P This is what we're doing on our WCF projects.

不知何故,我更喜欢直接使用svcutil.exe而不是使用Visual Studio的“添加服务引用”功能:P这就是我们在WCF项目中所做的事情。

#4


0  

I take your point, svcutil is definetly the more advanced way of adding and updating service references. Its just a fair bit more manual work when "right click, update reference" is so close to just working in a single step.

我认为,svcutil绝对是添加和更新服务引用的更高级方法。当“右键单击,更新参考”非常接近于只需一步操作时,它只需要更多的手动工作。

I guess we could create some batch files or something to just output the reference code. Even then, manually checking out and updating the service code with svcutil will probably be more work than just undoing the check out on the config.

我想我们可以创建一些批处理文件或只是输出参考代码。即使这样,使用svcutil手动检出和更新服务代码也可能比撤消配置中的检出更多。

Thanks for the advice in any case.

在任何情况下都要感谢您的建议。

#5


0  

What we do is we check out (from source control) the app.config and *.cs files that are autogenerated by the svcutil.exe utility, then we run a batch file that runs svcutil.exe to retrieve the service metadata. When it's done, we recompile the code, make sure it works, then check the updated app.config and *.cs files back in. It's a whole lot more reliable than using the oft-buggy "Add Service Reference" with Visual Studio.

我们做的是检查(从源代码控制)svcutil.exe实用程序自动生成的app.config和* .cs文件,然后我们运行一个运行svcutil.exe的批处理文件来检索服务元数据。完成后,我们重新编译代码,确保它有效,然后再检查更新的app.config和* .cs文件。它比使用Visual Studio的oft-buggy“添加服务引用”要可靠得多。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2008/09/16/71ec97af4e2086e52f2667a34f6e2189.html



猜您在找
具有basicHttpBinding和netTcpBinding的WCF服务;无法访问HTTP端点 - WCF service with both basicHttpBinding and netTcpBinding; can't access HTTP endpoint Angular 2 Visual Studio安装问题 - Angular 2 Visual Studio Setup Problems Visual Studio Express安装问题 - Problems with Visual Studio Express installation Visual Studio 2008关于Vista的问题 - Visual Studio 2008 on Vista problems 在Visual Studio 2008中为SQL 2005 HTTP端点Web服务添加SOAP标头 - Adding SOAP Headers for SQL 2005 HTTP Endpoint web service in Visual Studio 2008
智能推荐
 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告