WCF Dynamic Proxy (Microsoft)
Hi,
I downloaded the code form the link "WCF Dynamic Proxy (Microsoft)" to generate dynamic proxies.It works very fine.
But the senario which is covered in that is for using http,
I tried the dynamic proxy code for https and certificates(client and server) and it is failing.
Can anyone help me in this regards?
Sachin
Risposte
hi,
are you running into this error here :
- The remote certificate is invalid according to the validation procedure.
a quick solution (no not dirty
) would be to skip validation by using code like this:
Code SnippetServicePointManager.ServerCertificateValidationCallback +=
new System.Net.Security.RemoteCertificateValidationCallback(ReturnTrueInThisCallBackFunctionHere);hth, Allan
hi,
assuming clientCredentialType = "Certificate".
you will have to set the client certificate on the dynamicproxy.
now the proxy does not have support for this, but you can extend the proxy beyond recognition of course
.
start by creating a public method on the DynamicProxy (derived from DynamicObject)
Code Snippetpublic ClientCredentials Credentials
{
get
{
return (ClientCredentials)base.GetProperty("ClientCredentials");
}}
from your client code you can now set the certificate on the proxy.
Read more on this subject here
http://msdn2.microsoft.com/en-us/library/ms733102.aspx
I am not sure if this subject here is more a DynamicProxy thing than a WCF in general related question, if so the wcf list moderator can stop this thread....
but for now you should be armed with all you need to continue your work with this dynamic proxy.
hth, Allan
Tutte le risposte
hi,
are you running into this error here :
- The remote certificate is invalid according to the validation procedure.
a quick solution (no not dirty
) would be to skip validation by using code like this:
Code SnippetServicePointManager.ServerCertificateValidationCallback +=
new System.Net.Security.RemoteCertificateValidationCallback(ReturnTrueInThisCallBackFunctionHere);hth, Allan
Can you provide more detailed information on the failures? Exceptions you are seeing, error messages, etc.Hi,
I am getting this error
The document at the url https://.../addion.svc was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'DISCO Document' is 'There was an error downloading 'https://.../addion.svc?disco'.'.
- The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
- The remote certificate is invalid according to the validation procedure.
- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'https://.../addion.svc' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.Regards
Sachin
One more senario :- I have the url as https://.../addition.svc and I try to generate proxy through "Add Service Reference". It gives me same error....
-Sachin
Aha, so it seems you have some basic problems with the SSL config then?
Can you enable tracing on the service side to get more erro dsta?
okay I should be more explict here, I ran into the exact same issue here and if you do as I told in my previous post, it should fix your issue.
thanks Allan
Hi Allan,
Where do i write that code ?
Sachin
Hi,
before you call into the dynamic proxy.
you probably have some client kode that creates an instance of the dynamic proxy, you can place that validation check in your client start up code
int main()
{
validationcode.
call dynaproxy
}
I hope it solves your problem, it did the trick for me last year I remember.
Allan
Hi Allan,
It worked......
Thanks a ton........Well there is another problem now. The proxy is created but when i try to call the method in servcer i get following error..
Message : Exception has been thrown by the target of an invocation.
and
Inner Exception : The client certificate is not provided. Specify a client certificate in ClientCredentials.
I have added the code i am using and ablove mentioned exception is genrated in red marked line.
ServicePointManager
.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateCertificate); DynamicProxy additionProxy = factory.CreateProxy("IAddition"); // Call the Add service operation. DynamicDataContract value1 = new DynamicDataContract(factory.ProxyAssembly);value1.NumberOne = 10;
value1.NumberTwo = 20;
try{
Int32 result = (Int32)additionProxy.CallMethod("Add", value1.ObjectInstance);}
catch (Exception ex){
Console.WriteLine(ex.Message);}
Sachin....
Well, are you providing the client's cert?
In your code you do not - what does your config look like?
hi,
assuming clientCredentialType = "Certificate".
you will have to set the client certificate on the dynamicproxy.
now the proxy does not have support for this, but you can extend the proxy beyond recognition of course
.
start by creating a public method on the DynamicProxy (derived from DynamicObject)
Code Snippetpublic ClientCredentials Credentials
{
get
{
return (ClientCredentials)base.GetProperty("ClientCredentials");
}}
from your client code you can now set the certificate on the proxy.
Read more on this subject here
http://msdn2.microsoft.com/en-us/library/ms733102.aspx
I am not sure if this subject here is more a DynamicProxy thing than a WCF in general related question, if so the wcf list moderator can stop this thread....
but for now you should be armed with all you need to continue your work with this dynamic proxy.
hth, Allan
Hi Christian,
I am generating the proxy dynamically from the code i downloaded from following link
http://wcf.netfx3.com/files/folders/development_tools/entry6148.aspx
But the thing is that it works for url of http and fails to make proxy for https used with certificates(client and server).
Allan told a solution and it worked but when i call the method of service i get that exception.
We dont have any config file.
Sachin
Sorry Allan to bother you ,but could you please tell me more in detail what should I do. I am totally new in this technology so I have very lil idea.
Thanks for undertsnding
Sachin
btw...
speaking of .... I can resist ...must ... tell ... the world.
Take 1 Dynamic proxy.
stuff in some MetadataResolver for service discovery.
Add 1 SQL 2005 server (design a pub/sub schema....inspired by BTS 2006 schema)
Add some nice looking Infragistics controls for setting up publish/subscription.
Add a simple pub/sub service contract (make sure you handle XmlSerializer and DataContractSerializer correctly).
Finish off with one ounce of WWF for message retry handler.
add some secret ingredients for transformation.
Stir and cook it for a month and you will end up with:
a home grown Enterprise Service Bus, loosely coupled 0xBABE.
sorry for this OT
, hope you guys find some inspiration here.
@llan
- Show us the link to the baby!
Christian....I can't, I would have to kill you afterwards
...
but I have been talking to Mr. X about some code review...so one cold december morning perhaps
@llan
Hi Allan,
Thanks a lot .. It is working. Your help has been of great help to me and community. Thanks a ton.
Sachin
- Hi,
i'm testing WCF Dynamic Proxy but i have a problem.
When i create a DynamicProxyFactory i receive this error: "There was an error in importing the metadata".
Wsdl URL is http://webservices.dotnethell.it/codicefiscale.asmx?wsdl.
Can you help me?

