C#WSE 3.0 Webservice问题 [英] C# WSE 3.0 Webservice problem

查看:99
本文介绍了C#WSE 3.0 Webservice问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我刚刚注册到The Code Project,但是我已经有一段时间了,因为我在这里关注线程,我想祝贺所有人使这个页面很好的社区。



现在问题很好。



我正在尝试使用WSE 3.0在Web服务中设置安全性(我知道,它已被弃用......但它必须使用的技术)

我需要的安全性是证书标志&加密安全性(没有密码,只有共同证书)

我已经开始使用WSE示例中的示例了,但我遇到了以下问题。



Hello everybody.

I've just register to The Code Project, but its been a while since I follow threads in here, and I want to congrat all the community that makes this page as it good as it is.

Well to the question now.

I'm trying to set security in a webservice using WSE 3.0 (I know, I know, It's deprecated...but its the technology I have to use)
The security I need is a certificate sign & encrypt security (No password, just mutual certificate)
I've started with the example in WSE samples, but I run into the following problems.

public class TheClient {

    private readonly WebServiceWse webService;

    public TheClient() {
        webService = new WebServiceWse();
        // webService.SetPolicy("MyCustomPolicy");
    }





如果我取消评论行,它会出现以下错误。





if I unncoment the commented line, It rasises the following error.

ArgumentOutOfRangeException
Specified argument was out of the range of valid values.
Parameter name: Policy 'MyCustomPolicy' is not configured in the system





虽然我有它在我的策略文件中,app.config引用了它。



如果我留下评论的行,那么它会引发





although I have it in my policy file, wich is referenced by the app.config.

If I leave the line commented, then it raises

SoapHeaderException
Server unavailable. Try again later





但服务器已启动并运行,我可以通过浏览器访问网络服务。



顺便说一下。

解决方案包含3个项目



WebServer

客户端

测试Windows窗体应用程序



启动的是Windows窗体应用程序,那个,使用客户端访问网络服务器。

对于接缝,问题是客户端没有加载其应用程序配置,但WinForms app.config是加载的。



也许解决方案很简单,但作为C#和Visual Studio的新手,我无法找到任何。



如果有的话一个人可以给我一个提示我真的很感激。



提前谢谢



but the server is up and running, and I can access the webservice through browser.

By the way.
The solution consists of 3 projects

The WebServer
The Client
A Test Windows Form Application

The one that starts is the Windows Form application, and that one, uses the client to access the webserver.
For what it seams, the problem is that the Client does not load its app config, but the WinForms app.config is the one that loads.

Maybe the solution is simple, but as Im new to C# and Visual Studio, I cant find out any.

If any one can give me a hint I would really appreciat it.

Thanks in advance

推荐答案

尝试一下像这样:

将证书映射到用户帐户 [ ^ ]



这里有一些更有用的信息

IIS身份验证 [ ^ ]



希望这会有所帮助...



问候

Espen Harlinn
Try something like this:
Mapping Certificates to User Accounts[^]

Some more usefull info here
IIS Authentication[^]

Hopefully this helps ...

Regards
Espen Harlinn


发现问题如下



我的解决方案结构如下:



解决方案

|

+ - WebService(ASP webservice)

|

+ - 客户端(类库)

|

+ - TestUI(WinForms)应用程序)





WSE 3.0配置位于WebService web.config和policy.config(由web.config引用)文件中(对于服务ver)

在客户端的app.config和policy.config(由app.config引用)中(对于客户端)



客户的policy.config有一个政策部分如下



Find out that the problem was the following

My solution structure is as follwoing:

Solution
|
+-- WebService (ASP webservice)
|
+-- Client (Class Library)
|
+-- TestUI (WinForms Application)


The WSE 3.0 Configuration were in the WebService web.config and policy.config (referenced by web.config) files (For the server)
And in app.config and policy.config (referenced by the app.config) in Client (For the client)

The policy.config for the Client had a policy section as follows

<policy name="ClientPolicy">
  <mutualCertificate11Security establishSecurityContext="true" renewExpiredSecurityContext="true" requireSignatureConfirmation="true" messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true" ttlInSeconds="300">
    <clientToken>
      <x509 storeLocation="LocalMachine" storeName="My" findValue="CN=CertificateForClient" findType="FindBySubjectDistinguishedName" />
    </clientToken>
    <serviceToken>
      <x509 storeLocation="LocalMachine" storeName="AddressBook" findValue="CN=CertificateForServer" findType="FindBySubjectDistinguishedName" />
    </serviceToken>
    <protection>
      <request signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
      <response signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="true" />
      <fault signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
    </protection>
  </mutualCertificate11Security>
  <requireActionHeader />
</policy>





问题是,由于启动项目是TestUI,加载的app.config是该项目的app.config,而不是Client项目中的那个,因此,不在Client项目中加载policy.config。

这使得客户端中的以下行失败





The problem was that, as the start project was TestUI, the app.config that loads is the one on that project, and not the one in the Client project, thus, not loading the policy.config in Client project.
That makes that the following line in the client fails

webService.SetPolicy("MyCustomPolicy");



<带有ArgumentOutOfRangeException的




所以...我发现的解决方案...复制TestUI项目中的策略文件并从中引用它该项目中的app.config。

虽然我不喜欢这个解决方案......恕我直言他们是不同的项目,他们的配置应该是独立的。

我'我猜是有办法解决这个问题,但我无法弄清楚如何解决这个问题。如果有人知道如何,请告诉。



所以......这解决了问题。现在我遇到WSE错误状态:



WSE910:处理响应消息时发生错误,

和你可以在内部异常中找到错误。您还可以在Response属性中找到

响应消息。



和内部异常状态:



安全要求不满意,因为收到的消息中没有安全标题





I猜测证书问题。我几乎无法看看你的回答Espen,但是对于我所看到的,它可以帮助我解决出现的这个新问题。非常感谢您的回答。



希望这对任何遇到与我相同情况的人都有帮助。



干杯



with the ArgumentOutOfRangeException.

So...the solution I found...copy the policy file in the TestUI project and reference it from the app.config in that project.
Although I don't like that solution...IMHO they are different projects, and their configurations should be independient.
I'm guessing that there is a way to solve this, but I can't figure out how. If someone knows how, plase tell.

So...that solved the problem. Now I'm having a WSE error in which states:

WSE910: An error happened during the processing of a response message,
and you can find the error in the inner exception. You can also find
the response message in the Response property.

and the inner exception states:

Security requirements are not satisfied because the security header is
not present in the incoming message.

I'm guessing certificate problems. I barely could take a look at your answer Espen, but for what I see, it may help me to solve this new problem that appears. So thanks a lot for your answer.

Hope this helps to anybody that runs into the same situation that I did.

Cheers


嘿,我有同样的问题。你的解决方案是什么感谢。
Hey,I have the same issue.what is your solution thanks.


这篇关于C#WSE 3.0 Webservice问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆