strange behaviour calling method of wcf from powershell using new-webproxyservice - wcf

Can someone explain this to me:
I builded an really simple wcf service for testing purposes.
Consuming service from powershell using New-WebServiceProxy I found this stange behaviour:
if in wcf service I have this kind of Contract returning an int:
[OperationContract]
int GetDictionaryLength();
calling this method in powershell gives an error and the definition of the method is not what I would expect to see
PS C:\ps> $a | Get-Member getdictionarylength | fl *
TypeName :
Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_022s_pwdservice_svc_wsdl.PWDService
Name : GetDictionaryLength
MemberType : Method
Definition : System.Void
GetDictionaryLength(System.Int32&,
mscorlib, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089
GetDictionaryLengthResult,
System.Boolean&, mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
GetDictionaryLengthResultSpecified)
changing the contract like this:
[OperationContract]
string GetDictionaryLength();
do a great job called in powershell.
Why this?
WCF is in .net 4.0
Powershell is V2

Experimenting with your answer, and then finally discover this answer, it seems all your problems will go away if you simply add [XmlSerializerFormat] to the operation contract, and the method signature will return to normal. At least my problems did when testing against a 2.0 .Net framework and powershell.

finally I've discovered this:
PS C:\ps> [int]$int = 0
PS C:\ps> $bool = $true
PS C:\ps> $a.DictionaryLength([ref]$int, [ref]$bool)
PS C:\ps> $int
61
I've build a solution with .net 2.0 (powershell native framework) for a client application to consume my wfc (.net 4.0)
and the definition for method DictionaryLegth() was:
void myservice.DictionaryLength(out int DictyionaryLengthResult, out bool DictonaryLengthSpecified)

Related

WCF Service Error on generate code file with SVCUtil

I created a WCF service with net framework 4.0 on Windows OS;
and its works OK use SVCUtil to generate client code file.
but its failed on ubuntu apache with mono.
error info below:
exception :System.ServiceModel.Description.DataContractSerializerMessageContractImporter
details:
Due to the namespace "http://schemas.datacontract.org/2004/07/System" with data
contract name "MarshalByRefObject" reference types "System. MarshalByRefObject,
mscorlib, VerSion = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "
with import DataConTract does not match, so can't use. you need to remove the
type of the reference.
but how can i remove the type of the reference MarshalByRefObject on mono?
Any assistance would be appreciated. Thanks a bunch for your help.

Visual Studio 2012 install broke my 2010 WCF project

I've installed VS 2012 and am successfully using it on some web projects, but something with it has caused my web service project to break. I'm still using VS 2010 on the web service project and have not opened it in 2012.
Everything compiles and works correctly except when it tries to create an instance of a class in my referenced weblog project, then it throws this error:
This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked.
I can not find anywhere in the project where GetBufferlessInputStream is used explicitly.
If I jump over the weblog code, everything executes correctly.
I can't find anyone else who has received this error to try and narrow it down, any ideas where to start?
Stack
at System.Web.HttpRequest.get_InputStream()
at OAS.Web.Log.WebEvent..ctor(EventType type, HttpContext context, String applicationName)
at OAS.Web.Log.WebTrace..ctor(HttpContext context, String applicationName)
at OAS.Web.AdvisorServices.Extensions.OperationLoggerParameterInspector.BeforeCall(String operationName, Object[] inputs) in C:\SourceControl\OAS\IM.NET3.0\Web\AdvisorServices\OAS.Web.AdvisorServices.Extensions\OperationLogger\OperationLoggerParameterInspector.cs:line 54
**EDIT - Bonus Question
Why are these Framework 4.5 properties affecting my 4.0 solution?
Note : This issue has been fixed in .net 4.5.1. You can see the fix with 4.5.1. Once you have .net 4.5.1 add the following appSetting to switch back to the old behavior.
<configuration>
<appSettings>
<add key="wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode" value="true" />
</appSettings>
</configuration>
Here is how you can create a HttpModule to force ReadEntityBodyMode to be "classic" : http://blogs.msdn.com/b/praburaj/archive/2012/09/13/accessing-httpcontext-current-request-inputstream-property-in-aspnetcompatibility-mode-throws-exception-this-method-or-property-is-not-supported-after-httprequest-getbufferlessinputstream-has-been-invoked.aspx
To answer your other question (Why are these Framework 4.5 properties are effecting my 4.0 solution?):
.net 4.5 is an in-place upgrade of .net 4.0. So even if your project is targeting 4.0, since VS 2012 installs 4.5 runtime, some of the 4.5 behaviors take effect.
EDIT
Blog Entry:
In .net 4.5 WCF leveraged the buffer less input stream for scalability benefits. As a result when you try to access the HttpContext.Current.Request.InputStream property you may end up with the below exception, as the InputStream property tries to get you handle to the Classic stream as they both are incompatible.
“This method or property is not supported after
HttpRequest.GetBufferlessInputStream has been invoked.”
If you had a WCF 4.0 app which worked perfectly but on upgrading your .net framework to 4.5 you notice the service failing on accessing this property, here is the way to work-around the issue:
Add a simple HttpModule in the same WCF project which will access the InputStream property for each request before WCF reads it so that it will enforce the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility.
public class WcfReadEntityBodyModeWorkaroundModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context) {
context.BeginRequest += context_BeginRequest;
}
void context_BeginRequest(object sender, EventArgs e) {
//This will force the HttpContext.Request.ReadEntityBody to be "Classic" and will ensure compatibility..
Stream stream = (sender as HttpApplication).Request.InputStream;
}
}
Register this module in your web.config by adding these lines in <configuration> <modules> setting.
<system.webServer>
<modules>
<!-- Register the managed module -->
<add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly" />
</modules>
If you are using an app pool in classic mode, you will need to add the module to this section in the web.config:
<system.web>
<httpModules>
<add name="WcfReadEntityBodyModeWorkaroundModule" type="MyAssembly.WcfReadEntityBodyModeWorkaroundModule, MyAssembly" />
</httpModules>
If your project cannot be modified, then you can write this Http module in a separate assembly, GAC it separately and register this module in the web.config.
Now try accessing the service it should succeed for you!

Could not load type 'System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy'

I recently updated my XP machine now I can't run any of my WCF (.NET 3.5) web apps. It crashes when I call var wsHttpBinding = new WSHttpBinding(); with the following exception:
Could not load type
'System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy'
from assembly 'System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
I have read this post but it did not help. There are many posts at Microsoft that do not help either.

WCF Service + Entity Framework: How to send an entity?

some of my methods in the WCF Service returns an entities from the Entity Framework. I cannot add the Web Service reference in my Windows Phone 7 application because of that warning:
Custom tool warning: Cannot import
wsdl:portType Detail: An exception was
thrown while running a WSDL import
extension:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load type
'System.Runtime.Serialization.DataContractSet'
from assembly
'System.Runtime.Serialization,
Version=2.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e'.
XPath to Error Source:
//wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='IBarnGameServiceNEW'] D:\MGameWindowsPhone7\Service
References\ServiceReference3\Reference.svcmap
What's the reason ?
Run Visual Studio not under Administrator account. This helps me.

Issues calling a DLL from WCF/Silverlight

Trying to use a DLL that returns a list of tasks in the W2k3 server's Task Scheduler. Works great when I use it in a C# console app on the server, and using it on my computer (ASP.NET Dev Server), but when doing the same thing through the Silverlight-WCF RIA on the W2k3 server, it just wouldn't go. Silverlight returned "Object reference not set to an instance of an object" whenever it calls that DLL.
Fired up the Service Trace Viewer:
System.ServiceModel.FaultException`1[[System.ServiceModel.DomainServices.Hosting.DomainServiceFault, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Might it because I'm using a DomainService class, its hiccuping? Any particular security permission or config on IIS that needs to be done?
update:
Tried one last thing .... Identity impersonation to my domain username and password works! So what is the best way to set up IIS to get this to work?
Just stuck with using a Windows dummy account using identity impersonation. Don't like it, but it works.