Solved

Urgent WCF DATA CONTRACT

Posted on 2008-10-13
5
3,797 Views
Last Modified: 2013-11-26
I am trying to implement a WCF Webservice and I have created a datacontract, which code is as follows on my client I am trying to call the operation contract GetUser but I get that error.

I tried to pass a dataset, a string all the common types were returned sucessfully but not with MembershipUser or WCFMembershipUser.

Can you see where I havent done what I should?
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.DirectoryServices
Imports System.Data
 
Public Class membershipprovider
    Implements IMembershipProvider
 
 
    Public Sub New()
 
    End Sub
 
    Protected Function GetProvider(ByVal providerName As String) As System.Web.Security.MembershipProvider
        Return System.Web.Security.Membership.Providers("MyADMembershipProvider")
    End Function
 
    Protected Function ConvertUsers(ByVal user As System.Web.Security.MembershipUser) As WCFMembershipUser
        If user Is Nothing Then
            Return Nothing
        End If
 
        Dim membershipUser As WCFMembershipUser = New WCFMembershipUser(Now, user.Comment, user.CreationDate, user.Email, _
                                                                        user.IsApproved, user.IsLockedOut, user.LastLockoutDate, _
                                                                        user.ProviderUserKey, user.UserName, Now, True)
 
        Return membershipUser
    End Function
 
    Protected Function ConvertUser(ByVal provider As System.Web.Security.MembershipProvider, ByVal user As MembershipUser) As System.Web.Security.MembershipUser
        If user Is Nothing Then
            Return Nothing
        End If
 
        Dim membershipUser As New System.Web.Security.MembershipUser(provider.Name, _
            user.UserName, _
            user.ProviderUserKey, _
            user.Email, _
            user.PasswordQuestion, _
            user.Comment, _
            user.IsApproved, _
            user.IsLockedOut, _
            user.CreationDate, _
            user.LastLoginDate, _
            user.LastActivityDate, _
            user.LastPasswordChangedDate, _
            user.LastLockoutDate)
 
        Return membershipUser
    End Function
 
    Protected Function BuildUserList(ByVal collection As System.Web.Security.MembershipUserCollection) As List(Of WCFMembershipUser)
        If collection Is Nothing Then
            Return Nothing
        End If
        Dim list As New List(Of WCFMembershipUser)
        Dim user As System.Web.Security.MembershipUser
        For Each user In collection
            list.Add(ConvertUsers(user))
        Next
        Return list
    End Function
 
    Public Function ChangePassword(ByVal providerName As String, ByVal applicationName As String, ByVal username As String, ByVal oldPassword As String, ByVal newPassword As String) As Boolean Implements IMembershipProvider.ChangePassword
        Return GetProvider(providerName).ChangePassword(username, oldPassword, newPassword)
    End Function
 
    Public Function ChangePasswordQuestionAndAnswer(ByVal providerName As String, ByVal applicationName As String, ByVal username As String, ByVal password As String, ByVal newPasswordQuestion As String, ByVal newPasswordAnswer As String) As Boolean Implements IMembershipProvider.ChangePasswordQuestionAndAnswer
        Return GetProvider(providerName).ChangePasswordQuestionAndAnswer(username, password, newPasswordQuestion, newPasswordAnswer)
    End Function
 
    Public Function DeleteUser(ByVal providerName As String, ByVal applicationName As String, ByVal username As String, ByVal deleteAllRelatedData As Boolean) As Boolean Implements IMembershipProvider.DeleteUser
        Return GetProvider(providerName).DeleteUser(username, deleteAllRelatedData)
    End Function
 
    Public Function FindUsersByName(ByVal providerName As String, ByVal applicationName As String, ByVal usernameToMatch As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Collections.Generic.List(Of WCFMembershipUser) Implements IMembershipProvider.FindUsersByName
        Return BuildUserList(GetProvider(providerName).FindUsersByName(usernameToMatch, pageIndex, pageSize, totalRecords))
    End Function
 
    Public Function GetAllUsers(ByVal providerName As String, ByVal applicationName As String, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByRef totalRecords As Integer) As System.Collections.Generic.List(Of WCFMembershipUser) Implements IMembershipProvider.GetAllUsers
        Return BuildUserList(GetProvider(providerName).GetAllUsers(pageIndex, pageSize, totalRecords))
    End Function
 
    Public Function GetNumberOfUsersOnline(ByVal providerName As String, ByVal applicationName As String) As Integer Implements IMembershipProvider.GetNumberOfUsersOnline
        Return GetProvider(providerName).GetNumberOfUsersOnline()
    End Function
 
 
    Public Function GetPassword(ByVal providerName As String, ByVal applicationName As String, ByVal username As String, ByVal answer As String) As String Implements IMembershipProvider.GetPassword
        Return GetProvider(providerName).GetPassword(username, answer)
    End Function
 
 
    Public Function GetUserByUserKey(ByVal providerName As String, ByVal applicationName As String, ByVal providerUserKey As Object, ByVal userIsOnline As Boolean) As WCFMembershipUser Implements IMembershipProvider.GetUserByUserKey
        Return ConvertUsers(GetProvider(providerName).GetUser(providerName, userIsOnline))
    End Function
 
 
    Public Function GetUserByUsername(ByVal providerName As String, ByVal username As String) As MembershipUser Implements IMembershipProvider.GetUserByUsername
 
        Return Membership.GetUser(username)
    End Function
 
 
    Public Function ResetPassword(ByVal providerName As String, ByVal applicationName As String, ByVal username As String, ByVal answer As String) As String Implements IMembershipProvider.ResetPassword
        Return GetProvider(providerName).ResetPassword(username, answer)
    End Function
 
 
    Public Function UnlockUser(ByVal providerName As String, ByVal applicationName As String, ByVal userName As String) As Boolean Implements IMembershipProvider.UnlockUser
        Return GetProvider(providerName).UnlockUser(userName)
    End Function
 
 
    Public Function UpdateUser(ByVal providerName As String, ByVal applicationName As String, ByVal user As MembershipUser) As Object Implements IMembershipProvider.UpdateUser
        Dim provider As Security.MembershipProvider = GetProvider(providerName)
        provider.UpdateUser(ConvertUser(provider, user))
    End Function
 
 
    Public Function ValidateUser(ByVal providerName As String, ByVal applicationName As String, ByVal username As String, ByVal password As String) As Boolean Implements IMembershipProvider.ValidateUser
        Dim provider As Security.MembershipProvider = GetProvider(providerName)
 
        Return provider.ValidateUser(username, password)
    End Function
 
    Public Function CreateUser(ByVal username As String, ByVal password As String) As WCFMembershipUser Implements IMembershipProvider.CreateUser
        Return ConvertUsers(Membership.CreateUser(username, password))
    End Function
End Class
 
 
 
-------------Server Config----------------------------------------------
  <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false"/>
        <services>
 
            <service behaviorConfiguration="Service1Behavior" name="RoleProvider">
                <endpoint address="" binding="wsHttpBinding" contract="IRoleProvider">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
            <service behaviorConfiguration="MembershipProviderBehavior" name="membershipprovider">
                <endpoint address="" binding="wsHttpBinding" contract="IMembershipProvider">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
            <service behaviorConfiguration="ActiveDirectoryManagerBehavior" name="ActiveDirectoryManager">
                <endpoint address="" binding="wsHttpBinding" contract="IActiveDirectoryManager">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="Service1Behavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"  httpsHelpPageEnabled="true" httpHelpPageEnabled="true"/>
                    
                </behavior>
                <behavior name="MembershipProviderBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true" httpHelpPageEnabled="true"/>
                </behavior>
                <behavior name="ActiveDirectoryManagerBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true" httpHelpPageEnabled="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>
 
 
-------------------------Client Config---------------------------------
 <client>
            <endpoint address="http://localhost:4617/WCFAASecurityServices/MembershipProvider.svc"
               binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMembershipProvider"
               contract="IMembershipProvider" name="WSHttpBinding_IMembershipProvider">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:4617/WCFAASecurityServices/RoleProvider.svc"
                 binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRoleProvider"
                 contract="IRoleProvider" name="WSHttpBinding_IRoleProvider">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:4617/WCFAASecurityServices/ActiveDirectoryManager.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IActiveDirectoryManager"
                contract="IActiveDirectoryManager" name="WSHttpBinding_IActiveDirectoryManager">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>

Open in new window

0
Comment
Question by:Juliafrazer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:novynov
ID: 22706600
Exactly what error are you getting? I didn't see it described above.
0
 

Author Comment

by:Juliafrazer
ID: 22710641
The error I am getting is the following,

The underlying connection was closed: The connection was closed unexpectedly.

the cause is because I am trying to pass a type of MembershipUser or WCFMembershipUser (a datacontract that I ve created)  to the client, I tried to pass a String,a dataset and it works but not with a more complex type.
0
 

Author Comment

by:Juliafrazer
ID: 22711779
at System.Net.HttpWebRequest.GetResponse()    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)"
0
 
LVL 4

Expert Comment

by:novynov
ID: 22719673
Not sitting in front of a debugger looking at this, I may be grasping, but...

At a high level, there are a few places where an exception may likely originate in a WCF call: By the proxy during message creation and send, in the call itself, and on the service side when preparing the response. I've seen #1 and #3 happen due to serialization issues.

That said, what you describe almost sounds like #2. Some kind of exception is getting thrown on the server during message processing, and then the connection is lost/reset. Basically, it looks like the exception you're seeing may be a side effect of another problem.

To get to the bottom of this, we need to ascertain what exactly is causing the exception. The exception/fault that you are seeing looks like one of those exceptions that is "wrapping" the real cause. This obfuscation can happen when debugging things like WCF services - depending on how you handle your exceptions on the server side.

So, I'd recommend two things as a next step to discovering the root cause:

- Inspect the inner exception of the exception you're seeing on the client. Is it something besides null? Does it reveal anything of value?
- Place a debugger against your WCF service (remember, the debugger needs to be attached to the process of the service, not the service calling client. Place a breakpoint on call enter, and step through the entire call. Does the message come in? Does an exception happen somewhere in the call? Does the exception happen after all of the message handling routine is complete?

Let me know what you find out.
0
 

Accepted Solution

by:
Juliafrazer earned 0 total points
ID: 22719706
i think I found what it was, I took out some of the attributes of the WCFMembershipUser objects because they were having a Null value and somehow they were causing the problem. Now its working fine.

novynov thanks for your help.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question