Exception "Specified method is not supported" when call method from WCF web service with Net Core 3.1 - wcf

I'm trying to connect a Web service SOAP12 using WCF and .NET Core 3.1.
I've generate the Reference.cs using WCF connected service from Visual Studio 2019 (v16.6.2). VS2019 generates the file but shows some warnings.
I tried build a custom binding but always throw same error.
var customBinding = new CustomBinding(encodingBindingElement)
{
Elements = { new HttpTransportBindingElement //or HttpsTransportBindingElement for https:
{
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
}}
};
Already tried WSHttpBinding.
var binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential)
{
MaxBufferPoolSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
};
has anyone managed to consume WCF SOAP12 with .NET Core 3.1 that can help me?

This is a message security issue that is not yet supported by the .Net Core framework. This usually happens when the binding of the service endpoint contains elements (functions) that are not supported in .NET Core, such as certain security elements (message security). .net core 3.1 does not yet support SymmetricSecurityBindingElement.
.Net core only supports the following bindings:

Related

Xamarin.Forms Add Connected Service on WCF only generated async method

I just begun to do Xamarin.Forms with .Net Standard 2.0 (PCL) project. I'm trying to consume my WCF web service but never got it successfully done.
I have created a simple WCF as below
[ServiceContract]
public interface IWcfConnection
{
[OperationContract]
string GetHelloWorld();
}
the implementation as below
public class WcfConnection : IWcfConnection
{
public string GetHelloWorld()
{
return "Hello World";
}
}
It's a very simple WCF, when I go to my Xamarin.Forms and right click on the "Connected Service", there is no "Add Web Service", but only "Add Connected Service", so I selected that as below
Then select "Microsoft WCF Web Service Service Provider"
Select the option as below (I untick everything because if I add more than 1 service, it will crash)
When I look into the reference.cs created, there is only async method created.
public System.Threading.Tasks.Task<string> GetHelloWorldAsync()
{
return base.Channel.GetHelloWorldAsync();
}
1) May I know why only async is created? Is it for .net standard and core, only async services will be created? As I read somewhere.
2) If so, how do I consume the web service?
In my xaml.cs file, I did the following,
WcfConnectionService.WcfConnectionClient client = new WcfConnectionService.WcfConnectionClient(new WcfConnectionService.WcfConnectionClient.EndpointConfiguration());
string abc = client.GetHelloWorldAsync().GetAwaiter().GetResult();
But I'm getting error and unable to work accordingly. Anybody got any idea?
Unhandled Exception:
System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Error in deserializing body of request message for operation 'GetHelloWorld'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetHelloWorld' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetHelloWorldAsync' and namespace 'http://tempuri.org/'
At the moment Xamarin apps aren't compatible with the Task-based asynchronous WCF proxy methods that the WCF Web Service Reference connected service provider generates for .NET Standard projects (bugzilla.xamarin.com Bug 51959).
Generate an older compatible style of WCF proxy methods via checked "Generate Synchronous Operations" checkbox on Configure WCF Web Service Reference screen:
Consume the web service:
KimlikServiceReference.KPSPublicSoapClient soapClient = new KimlikServiceReference.KPSPublicSoapClient(KimlikServiceReference.KPSPublicSoapClient.EndpointConfiguration.KPSPublicSoap);
//KimlikServiceReference.TCKimlikNoDogrulaResponse response = soapClient.TCKimlikNoDogrulaAsync(TCKimlikNo, Ad, Soyad, DogumYili).Result;
bool result = soapClient.TCKimlikNoDogrula(TCKimlikNo, Ad, Soyad, DogumYili);

how can I add a JSONP endpoing for WCF Ria Services to enable cross-domain calls?

I'm aware that WCF RIA Services has a Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory that I can use to enable JSON.
I need to enable cross-domain calls via JSONP. Is there an existing DomainServiceEndpointFactory that will accomplish this?
I just needed to do this - I overrode JsonEndpointFactory and tinkered with the binding in there, then added an endpoint using the new class.
namespace Bodge
{
public class JsonPEndpointFactory : JsonEndpointFactory
{
public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost)
{
IEnumerable<ServiceEndpoint> endPoints = base.CreateEndpoints(description, serviceHost);
foreach (ServiceEndpoint endPoint in endPoints)
{
if (endPoint.Binding is WebHttpBinding)
{
((WebHttpBinding)endPoint.Binding).CrossDomainScriptAccessEnabled = true;
}
}
return endPoints;
}
}
}
<endpoints>
<add name="JSONP" type="Bodge.JsonPEndpointFactory, Bodge, Version=1.0.0.0"/>
</endpoints>
Then access your service with the endpoint and the callback query param e.g.
http://blah/service.svc/JSONP/GetStuff?callback=callbackname
Hope that helps,
Chris.
Formatting in comments isn't great, so for future reference here are the required usings and assemblies.
Thanks very much, that's exactly what I needed!for future reference, these are the using statements:
Namespaces:
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using Microsoft.ServiceModel.DomainServices.Hosting;
Assemblies
NETFX 4.0
System.ServiceModel
System.ServiceModel.Web
WCF RIA Services V1.0 SP2 RC
System.ServiceModel.DomainServices.Hosting
System.ServiceModel.DomainServices.Server
WCF RIA Services Toolkit (September 2011)
Microsoft.ServiceModel.DomainServices.Hosting

Consume a wcf duplex service in console application

I have a wcf duplex service with work fine in silverlight. but the same service I want to consume in windows console application. My code as follow:
var context = new InstanceContext(this);
var address = new EndpointAddress("http://localhost:31881/PubSubService.svc");
var binding = new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement());
var client = new PubSubClient(context, binding, address);
client.Publish("topic", "content");
App.config is "empty":
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
It give me an error:
Binding 'CustomBinding' doesn't support creating any channel types. This often indicates that the BindingElements in a CustomBinding have been stacked incorrectly or in the wrong order. A Transport is required at the bottom of the stack. The recommended order for BindingElements is: TransactionFlow, ReliableSession, Security, CompositeDuplex, OneWay, StreamSecurity, MessageEncoding, [...]
Could you help me? Thanks in advance.
The problem is that PollingDuplexHttpBinding and related binding element is available only in Silverlight API. So when you start new .NET project (Console application in your case) you can't use the same code, because .NET does not contain PollingDuplexBindingElement

Silverlight 4 NetTcpBinding programmatic configuration

I'd like to configure a NetTcpBinding programatically for a silverlight 4 client. (NetTcpBinding is now supported)
Here is the code I use to do this for a Windows Forms client:
EndpointAddress endpointAddress = new EndpointAddress(uri);
NetTcpBinding netTcpBinding = new NetTcpBinding();
MyServiceClient agentClient = new MyServiceClient(new InstanceContext(this), netTcpBinding, endpointAddress);
For silverlight I added references to System.ServiceModel.Extensions and System.ServiceModel.NetTcp, but this is not not enough : I'm not able to find a NetTcpBinding class.
Where is this class if it exists? Does an equivalent syntax exists? The silverlight 4 runtime must be doing this somehow when a configuration file is used.
You can use a custom binding in place of NetTcpBinding : the code below is working, but I don't know if this is the recommended pattern.
BinaryMessageEncodingBindingElement messageEncoding = new BinaryMessageEncodingBindingElement();
TcpTransportBindingElement tcpTransport = new TcpTransportBindingElement();
CustomBinding binding = new CustomBinding(messageEncoding, tcpTransport);

Reading from ServiceReferences.ClientConfig in WCF in Silverlight 3 in a dynamically loaded .xap file

I'm using Silverlight 3 Prism (CAB) with WCF
When I call a WCF service in a Prism module, I get the same error:
"Could not find default endpoint element that references contract 'IMyService' in the service model client configuaration section. This might be because no configuaration file was found for your application or because no end point element matching this contract could be found in the client element"
It turns out that its looking in the Shell's .xap file for a ServiceReferences.ClientConfig file, not in the module's ServiceReferences.ClientConfig file. I added my endpoint and binding to the existing ServiceReferences.ClientConfig file in my Silverlight Shell application (it calls it's own WCF services).
Then I had to rebuild the Shell app to generate the new .xap file for my Web project's ClientBin folder.
Next I changed to setting up the service in code:
// create the binding elements
BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement();
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement()
{ MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue};
HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement()
{ MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };
// add the binding elements into a Custom Binding
CustomBinding customBinding;
if (Application.Current.Host.Source.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase))
{
customBinding = new CustomBinding(binaryMessageEncoding, httpsTransport);
}
else
{
customBinding = new CustomBinding(binaryMessageEncoding, httpTransport);
}
// create the Endpoint URL
EndpointAddress endpointAddress = new EndpointAddress(
"http://localhost/Test/TestModule/Test.TestModule.WCF/TestModuleService.svc");
// create an interface for the WCF service
var service = new TestModuleServiceClient(customBinding, endpointAddress);
This post deals with a similar situation:
http://blogs.southworks.net/matiasb/2009/06/20/how-to-consume-wcf-services-from-composite-application-guidance-for-wpf-and-silverlightprism-v2-modules/
Thanks,
Damian Schenkelman
http://blogs.southworks.net/dschenkelman