logo
down
shadow

Pass single complex type parameter to wcf operation issue


Pass single complex type parameter to wcf operation issue

By : choopchiq
Date : November 17 2020, 11:52 AM
around this issue There are multiple solutions.
The best would be to compile your contract (data and service) objects into a common client assembly and use that same assembly on both the client and server side (so there's no need to create a service reference at all).
code :


Share : facebook icon twitter icon
For request in operation UploadPhotoStream to be a stream the operation must have a single parameter whose type is Strea

For request in operation UploadPhotoStream to be a stream the operation must have a single parameter whose type is Strea


By : David Shi
Date : March 29 2020, 07:55 AM
Any of those help For future viewers, if you want to achieve this goal, wherein you will be able to put multiple parameters together with Stream, what you need to do is to avoid using SVC files to create Rest or Soap service. Instead add this on your services project, Global.asax file, the make route table, like for example:
code :
public class Global : System.Web.HttpApplication
{
    RouteTable.Routes.Add(new ServiceRoute("MyApp/rest/Photo", new WebServiceHostFactory(), typeof(PhotoComponent)));
}  
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class PhotoComponent : Interfaces.IPhotoComponent
{
    public bool UploadPhotoStream(string productid, string photoid, Stream fileData)
    {
        // some code....
    }
}

[ServiceContract]
public interface PhotoComponent
{
    [OperationContract]
    [WebInvoke(UriTemplate = "UploadPhotoStream/{productid}/{photoid}", Method = "POST")]
    bool UploadPhotoStream(string productid, string photoid, System.IO.Stream fileData);
}  
<services>  
  <service behaviorConfiguration="Default" name="StackSample.Logic.PhotoComponent">
    <endpoint behaviorConfiguration="JSON" binding="webHttpBinding" bindingConfiguration="RESTSecureTransfer" contract="StackSample.Interfaces.PhotoComponent" />
  </service>
</services>   
https://127.0.0.1/MyApp/rest/Photo/UploadPhotoStream/{productid}/{photoid}  
How to pass a complex type parameter (DTO object) to GET requests?

How to pass a complex type parameter (DTO object) to GET requests?


By : kevin lawrence
Date : March 29 2020, 07:55 AM
seems to work fine Why does passing data in the URI seem redundant? The HTTP spec says that GET methods are not to use content sent in the body. This is primarily to facilitate caches being able to cache responses based only on the URI, method and headers. Requiring caches to parse the body of a message to identify a resource would be very inefficient.
Here is an basic extension method that will do the grunt work for you,
code :
 public static class UriExtensions
    {
        public static Uri AddToQuery<T>(this Uri requestUri,T dto)
        {
            Type t = typeof (T);
            var properties = t.GetProperties();
            var dictionary = properties.ToDictionary(info => info.Name, 
                                                     info => info.GetValue(dto, null).ToString());
            var formContent = new FormUrlEncodedContent(dictionary);

            var uriBuilder = new UriBuilder(requestUri) {Query = formContent.ReadAsStringAsync().Result};

            return uriBuilder.Uri;
        }
    }
 public class Foo
    {
        public string Bar { get; set; }
        public int Baz { get; set; }
    }
    [Fact]
    public void Foo()
    {
        var foo = new Foo()
        {
            Bar = "hello world",
            Baz = 10
        };

        var uri = new Uri("http://example.org/blah");
        var uri2 = uri.AddToQuery(foo);

        Assert.Equal("http://example.org/blah?Bar=hello+world&Baz=10", uri2.AbsoluteUri);
    }
Azure Mobile Service - Consume POST Operation With Complex Type Parameter

Azure Mobile Service - Consume POST Operation With Complex Type Parameter


By : user3414821
Date : March 29 2020, 07:55 AM
To fix this issue I have created a custom controller with the following method: , You should be able to do something like:
code :
var loginParams = new LoginRequest() { ... };
var result = await Client.invokeApiAsync<LoginResult, string>("CustomLogin", loginParams);
public async Task<HttpResponseMessage> InvokeApiAsync(string apiName, 
  HttpContent content, HttpMethod method, IDictionary<string, string> 
  requestHeaders, IDictionary<string, string> parameters)

public async Task<U> InvokeApiAsync<T, U>(string apiName, T body, 
  HttpMethod method, IDictionary<string, string> parameters)

public async Task<JToken> InvokeApiAsync(string apiName, JToken body,    
  HttpMethod method, IDictionary<string, string> parameters)
Web Service: Single String Parameter Or Complex Type Parameters

Web Service: Single String Parameter Or Complex Type Parameters


By : user3911108
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I would never send an XML string. First of all, "XML" is not the same thing as "string". They do not follow the same rules.
Any reasonable client can accept a complex type consisting of primitive types and lists or arrays of primitive types, recursively (C# syntax):
WCF Service application: The operation must have a single parameter whose type is Stream

WCF Service application: The operation must have a single parameter whose type is Stream


By : JacobK
Date : March 29 2020, 07:55 AM
should help you out If you switch to (BasicHttp or WSHttp )Binding then you can achieve your goal by composing a single data type including all your custom parameters via properties and the Stream object itself. Then you are making use of messaging style instead of RPC conversation. And pls pay attention to [MessageContract] family of WCF DTO decorators.
Related Posts Related Posts :
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • How Can You Bind a List<String> to a StackPanel
  • WPF Application Update Best Practices - Architectural Explanation
  • System.UnauthorizedAccessException in Server.MapPath()
  • Connecting and Using SQL Compact Edition in a WPF application
  • C#: weird ref in constructor to behave like "virtual field"
  • C# XDocument Load with multiple roots
  • How to decide what goes in the Domain or Application Project in a "DDD" solution?
  • How to get/set a property of an interface that is not always implemented
  • Read-only array field in unsafe struct
  • i got "Invalid attempt to call Read when reader is closed" when using sqldatareader how to solve it in a three
  • Why should I encapsulate objects in using if there is garbage collection
  • How to load Word document from byte array
  • Caliburn.Micro and ContextMenu for DataGrid Row
  • Linq "join" with a IList<T> getting "Error Unable to create a constant value.."
  • How to draw red wavy line under words in RichTextBox c# winform
  • HttpPostedFileBase returns Null MVC3
  • Refresh Dropdownlist in webform
  • How to convert serialized byte array back to its text form
  • How to do a loop to check all the variables at the same time for C#?
  • Facebook Sentiment Analysis API
  • Counting occurrences of specific letters in string
  • Module 'System.Data.Linq' Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089' should be referenced
  • C# MVC Dynamically create view model
  • Get Executing Path of C# application when using nunit with Jenkins
  • GDI count stable near 100 but Handle count keep increasing
  • Problem adding string value to ViewBag from an MVC Action using TempData
  • Reading Excel file on condition
  • what is windows programming from C++, C# and Java perspective?
  • How to deal with C# object references in MongoDB?
  • How to create a list from filtering 2 lists with linq to object
  • Webclient calls to DownloadString cause my app to freeze
  • How to create a JSON WebService in c# ASP.Net with a valid JSON output and query with JQuery/Ajax
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org